NSNotification以破碎的对象到达

时间:2011-07-21 10:47:02

标签: objective-c cocoa nsnotifications

我以这种方式发布通知:

...
IVSession *newSession = [[[IVSession alloc] initWithDictionary:propertyDict] autorelease];     

NSDictionary *notifParams = [NSDictionary dictionaryWithObject:newSession  forKey:@"session"];        
NSNotification *newSessionNotif = [NSNotification notificationWithName:IVNewSessionNotificaiton object:self userInfo:notifParams]; 
...

IVSession界面:

@interface IVSession : IVMappableObject {
    NSString *_ssid;
    NSNumber *_uid;    
}

@property (nonatomic,retain) NSString *sessionID;
@property (nonatomic,retain) NSNumber *userID;

和init方法:

- (id)initWithDictionary:(NSDictionary*)dict
{
    if ((self = [super init]))
    {
        NSDictionary *mapping = [self elementToPropertyMappings];
        for (NSString *key in mapping)
            [self setValue:[dict objectForKey:key] forKey:[mapping objectForKey:key]];
    }    
    return self;
}

但是在调用此通知的方法中,我收到了损坏的newSession对象 - 其属性ssiduid是无效的摘要:

-(void)didOpenSession:(NSNotification *)newSession
{
    if (receivedSession)
        [receivedSession release];
    receivedSession =  [[newSession userInfo] objectForKey:@"session"];
} 

我的错在哪里?

1 个答案:

答案 0 :(得分:0)

代码对我来说没问题...你是否确认过IVSession对象在组装之后,但在发布通知之前包含了你的期望?