RE: Simple Messaging/NSMutableArray question
RE: Simple Messaging/NSMutableArray question
- Subject: RE: Simple Messaging/NSMutableArray question
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Tue, 22 Oct 2002 17:43:21 -0400
I'm not sure whether any of these are the answer to your problem, but two
things about your code struck me as suspicious:
>
- (IBAction)copyRecord:(id)sender {
>
[self addToArray];
You have an addToArray: method that takes an NSString as an argument, but
your are not passing any argument here, so my guess is that nothing happens.
(Or maybe there are both an addToArray method and an addToArray: (note the
colon) method?)
>
TestArray1 *aCopy = [[TestArray1 alloc] init];
You seem to have subclassed NSMutableArray. Arrays are actually class
clusters and they are quite tricky to subclass.
>
[aCopy addToArray:@"This is a copied String"];
>
[aCopy release];
>
}
What you appear to have done is create an instance of TestArray1, added a
string to it, and then released it. So of course that instance goes poof
and vanishes.
On to your question...
>
All I want to do is send a string from one object
>
and have it populate an array in another object.
There are at least two ways of doing this.
Option 1: The sending object "knows about" the receiving object because it
holds a reference to that object. This seems to be what you had in mind,
but you are sending messages to an object and then killing it. You seem to
think there should be another instance of the TestArray1 class rattling
around in your application. If you give your sending object a reference to
the intended receiver (not just another instance of the same class), the
sender can communicate directly with the receiver.
Option 1a: Use a controller object in between the two data objects. The
controller could have pointer to both data objects and pass the message
along.
Option 2: The receiving object can register for a notification, say,
PNAddToArray1Notification, and can specify a method to be called. Typically
the receiving object would register in its -init method. The sending object
then can fire off a notification. The notification center will send a
message to the receiving object, and the method specified will be invoked.
Or maybe I've got it completely wrong. I'm not sure I understood who was
object 1 and who was object 2 in your code.
Jonathan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.