objective c - EXC_BAD_ACCESS while filling in the dictionary (?) -


void countlyrecordeventsegmentationcountsum(const char * key, const char * segmentation, int count, double sum) {     nsstring * seg = creatensstring(segmentation);     nsarray * entries = [seg componentsseparatedbystring:@"`"];     nsdictionary * dict = [nsdictionary dictionary];     (id entry in entries)     {         nsarray * keyvalue = [entry componentsseparatedbystring:@"|"];         [dict setvalue:[keyvalue objectatindex:1] forkey:[keyvalue objectatindex:0]];     }     [[countly sharedinstance] recordevent:creatensstring(key) segmentation:dict count:count sum:sum]; } 

i put "?" in title because i'm not entirely sure if problem in code above that's best guess. i'm integrating countly ios plugin unity , 1 of countly plugin's methods take nsdictionary * argument. don't know how send dictionary c# objective-c i'm storing dict in string, sending objective-c , recreating dictionary (the code above).

but that's not relevant. know exc_bad_access has unfreed resources or sth maybe can see i'm doing wrong (i don't know objective-c @ all, writing few lines needed plugin).

edit: unity sample:

// converts c style string nsstring nsstring * creatensstring (const char * string) {     if (string)         return [nsstring stringwithutf8string: string];     else         return [nsstring stringwithutf8string: ""]; } 

the error you've made trying modify immutable version of nsdictionary.

one cannot modify contents of nsdictionary after it's initialization. should use nsmutabledictionary instead.

here documentation on nsmutabledictionary. , here an example of how create mutable version of immutable object conforms nsmutablecopying protocol.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -