views:

391

answers:

3

Hi

I am new to this objective c

I have created the one mutable array in appdelegate. I am trying to retrieve values of that mutable array in another app. But it is crashing at that point. below is the code i have declared in appdelegate

savedLocation = [[NSMutableArray alloc] init];
 savedLocation = [[NSMutableArray arrayWithObjects:
       [NSNumber numberWithInteger:0],
       nil] retain];

below is code i trying to access the array values in another application through appdelegate

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
 NSInteger selection = [[appDelegate.savedLocation objectAtIndex:0] integerValue];

but it is crashing at

NSInteger selection = [[appDelegate.savedLocation objectAtIndex:0] integerValue];

please tell me the reason why it is crashing? and correct way also

+1  A: 

If you really have 2 different Objective-C applications running, keep in mind that each one will have its own [UIApplication sharedApplication]. If I understand your question correctly, you are assuming that you will be able to pass information between applications using this mechanism and that is simply not the case. Each app will have its own sharedApplication and corresponding app delegate, and will not be able to see the members of the other.

Since you are using UIApplication (rather than NSApplication), I am inferring that you are using Cocoa Touch (for iPhone and iPod Touch), and so you are probably interested in the mechanisms that are available for sharing data between applications. There are a number of possible approaches, including a custom URL handler (to allow one app to launch the other app with some particular parameters), or using a network-dependent sync mechanism where you store data from both applications in some shared server location on the Internet. You should keep in mind, however, that:

  1. Only one of your applications will ever be running on the Cocoa Touch device at any one time. So, the in-memory member variables of the app delegate will be released as soon as the app that instantiated them exits (to make way for the other app).

  2. There is no way I know of for one Cocoa Touch application to read data saved by another Cocoa Touch application onto the device. The operating system strictly sandboxes all individual applications running on the device so one cannot read data saved by another.

This question is similar to what I think you're asking.

Gene Goykhman
A: 

OK

Thanx for your reply.

iF i want to access the Mutable array in another view of same application, is this below code fine. I have tried this, but it is crashing in the same point which i have mentioned in the above.

below is code i trying to access the array values in another view through appdelegate

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
 NSInteger selection = [[appDelegate.savedLocation objectAtIndex:0] integerValue];

but it is crashing at

NSInteger selection = [[appDelegate.savedLocation objectAtIndex:0] integerValue];
need
outis
A: 

If you are using Objective-C and Cocoa for a Mac OS X application you can find many system to pass information between two running applications i.e. using Notifications, the File System, Distant Objects, the PasteBoard some useful information can be found here: http://developer.apple.com/mac/library/navigation/index.html#section=Topics&topic=Interapplication%20Communication

scriba