I am new to iOS programming, and have recently learned a valuable lesson in memory management. I solved my problem, but I am not sure if it was the right way to do it.
UserFetcher *userFetcher = [[UserFetcher alloc] init];
[userFetcher setDelegate: self];
[userFetcher fetchData];
In this code, userFetcher makes a REST call using RestKit to an external server, i.e. UserFetcher wraps RestKit. When Restkit returns the values to userFetcher, an error is thrown since userFetcher has been destroyed. This happens because the parent method where UserFetcher was created (the code above) finished executing, and I assume ARC dealloced it.
I solved this problem by making a private property UserFetcher of type (strong, nonatomic). I was wondering whether that is the best way of solving it? Or could my design be improved.
You solved it properly. You need a strong reference to this object. When you are for sure done with it then “userFetcher=nil;” will release it.