NSNotification 到达时对象已损坏
我以这种方式发布通知:
...
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
对象 - 其属性 ssid
和 uid
是无效摘要:
-(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代码对我来说看起来不错...您是否在组装之后、发布通知之前验证了 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?