Loading properties from JSON, getting “message sent to deallocated instance”

心不动则不痛 提交于 2019-12-23 04:04:27

问题


So I load my custom object from a web service and am trying to store the properties as NSStrings but keep running into this error:

-[CFString _cfTypeID]: message sent to deallocated instance 0x100d3d40
-[CFString retain]: message sent to deallocated instance 0x100d3d40

I enabled zombies, but that's not really showing me a solution.

My properties are defined as:

@property (strong, nonatomic) NSString *title;
@property (assign, nonatomic) NSString *ID;
@property (strong, nonatomic) NSString *redLabel;
@property (strong, nonatomic) NSString *greenLabel;

Then I create an instance of my object and call the webservice

QuickList *list = [[QuickList alloc] init];
[list loadLatestQuickList];

And finally, inside loadLatestQuickList...

NSURLRequest *request = // create a GET request...
[NSURLConnection sendAsynchronousRequest:request queue:notMainQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
    NSError *parsingError;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&parsingError];
    if (!parsingError && [json isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dataDictionary = [json objectForKey:@"data"];
        NSDictionary *quickListDictionary = [dataDictionary objectForKey:@"QuickList"];

        NSString *ID = [quickListDictionary objectForKey:@"id"];
        NSString *title = [quickListDictionary objectForKey:@"name"];
        NSString *redLabel = [quickListDictionary objectForKey:@"red_label"];
        NSString *greenLabel = [quickListDictionary objectForKey:@"green_label"];

        self.ID = ID;
        self.title = title;
        self.redLabel = redLabel;
        self.greenLabel = greenLabel;

        // tell a channel that everything is loaded
    }
    else {
        NSLog(@"%@",parsingError);
    }
}];

Now whenever I try to access list.ID or some other property I get the "deallocated instance" error. Any thoughts as to why I'm getting this error?


回答1:


Your ID property should be strong as well.



来源:https://stackoverflow.com/questions/11594413/loading-properties-from-json-getting-message-sent-to-deallocated-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!