In my iPhone App.
Problem: When I am trying to get the value from dictionary in model class it is giving me the nil values.
Why this is happening, is this the memory management issue ?
I did this,
I am passing NSDictionary, from my viewController to NSMutableArray Category and from that I am passing it to my Modelclass.
If you want to see the coding,
In my ViewController.m file
[arrayNews convertToNewsArticles];
In my NSMutableArray category I am calling method convertToNewsArticles.
for(NSMutableDictionary *dictionary in self) {
NewsArticle *newsArticle=[[NewsArticle alloc] initWithDictionary:dictionary]; [arrayConverted addObject:newsArticle]; }
I am talking about this dictionary that I am passing.
Here is my Model class
-(NewsArticle*)initWithDictionary:dictionary{
self.title=dictionary[@"title"]; self.author=dictionary[@"author"]; self.urlString=dictionary[@"url"]; return self;}
Update:
I solved by using IAModelBase class on GitHub.IAModelBase
initWithArray. This code belongs somewhere else; probably in the object that is fetching the news articles, but if you insist on doing this you just need to say[self addObject:newsArticle]Have you read the Subclassing notes in the NSMutableArray class reference? - Paulw11