NSNotification 到达时对象已损坏

发布于 2024-11-26 01:42:06 字数 1305 浏览 3 评论 0原文

我以这种方式发布通知:

...
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"];
} 

我的错在哪里?

i'm posting notification in this manner:

...
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:

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

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

and init method:

- (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;
}

but at the method, called for this notification, i'm receiving broken newSession object - its properties ssid and uid are invalid summaries:

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

where is my fault?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

策马西风 2024-12-03 01:42:06

代码对我来说看起来不错...您是否在组装之后、发布通知之前验证了 IVSession 对象包含您期望的内容?

code looks ok to me... have you verified that the IVSession object contains what you expect it to, after assembling things, but prior to posting the notification?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文