views:

25

answers:

2

Here is my code snippit:

- (void) getData: (NSNotification *)aNotification{
NSData *data = [[aNotification userInfo] objectForKey:NSFileHandleNotificationDataItem];

if ([data length])
{
    return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
} else {
    [self stopProcess];
}

[[aNotification object] readInBackgroundAndNotify];  
}

Ok, so how do I set an NSString to the value of getData anywhere else in my application?

Thanks, Elijah

A: 

Well, first of all, you can't return an NSString object from a void function.

Secondly, it looks like this method is triggered via the notification system. Setting an NSString to a value of getData anywhere in your application would require having (a) an object, and (b) a way to set an NSString on that object.

Basically, notifications happen asynchronously. Your getData method can only extract the string value and pass it via a message to other objects it knows about.

mipadi
A: 

Assuming this notification message is a member of a class, I would use an instance variable to store the latest value of the string so that other clients that need it could read the last known value.

David
Ok....I don't want to use NSNotification. I just want to get the data. How do I do that? BTW...this is from the moriarity app
Elijah W.
The code you posted USES a notification and it looks like a notification handler. If you are listening to notifications, you will have to do it somewhat similarly as your code, capturing the value of the notification somewhere.
David