I create a new “View-based Application” project and modify the didFinishLaunchingWithOptions: method as follow.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
downloader = [[InternetIOProcess alloc] init];
[downloader initWithServer:[NSURL URLWithString:@"http://www.test.com"] ];
return YES;
}
InternetIOProcess is a NSObject with two variables, and a method:
@interface InternetIOProcess : NSObject {
NSMutableArray* downloadingFile;
NSURL* serverAddress;}
@property (nonatomic,retain) NSMutableArray* downloadingFile;
@property (nonatomic,retain) NSURL* serverAddress;
-(void) initWithServer:(NSURL*) server;
the implementation of InternetIOProcess is:
@implementation InternetIOProcess
@synthesize downloadingFile,serverAddress; //,serviceuploadingQueue,;
-(void) initWithServer:(NSURL*) server
{
downloadingFile = [NSMutableArray array];
serverAddress = server;
}
And then, I write a IBAction in UIViewController response to a button “touch up inside” event:
-(IBAction) test:(id)sender
{
MyAppDelegate* d = (MyAppDelegate*)[UIApplication sharedApplication].delegate;
InternetIOProcess* thedownloader = d.downloader;
//value of "thedownloader" incorrect.
}
Try to access “thedownloader” here, its member “downloadingFile, serverAddress” both give random bad values!
Anybody know why can’t I access this object?
The problem lies here with you not retaining the array and the server and bad naming convention of init. It looks like your custom init method is not getting called.
Try making the following changes