I wrote this function in my RootViewController. appRecord is an object holding an XML attribute.
- (NSString*) getString:(int)row{
AppRecord *appRecord = [self.entries objectAtIndex:row];
NSString *appName = appRecord.appName;
return appName;
}
I want to use this function again by writing this:
RootViewController *record = [RootViewController new];
NSString *appsName = [record getString:0];
NSLOG(appsName);
After I compiled, it didn’t return anything, but it works and returns appsName if I use this function inside the RootViewController class ([self getString:0]), so I know there is no problem with the function. When I tried to change return appName to return @"test", it worked and returned something when I accessed it from the other class.
This means there is a problem with this appRecord; it was returned inside the class but returns nothing when I access it from another class.
How to solve this problem?
You are getting your AppRecord from
self.entriesin the instance of RootViewControllerrecord. This means unless yournewinitializer initializes and populates itsentriesvariable (array by the looks of things) before you callgetString:, it won’t be able to return anything since that array is empty.Beyond that, I don’t know if you want your
getString:(int)method to access a different array, or if the problem is in your initialization ofRootViewController(more likely)