开发者

Problem with setting a value

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 o开发者_C百科f getData anywhere else in my application?

Thanks, Elijah


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜