NSNotification userinfo的例子?

我有一个使用CGPoints定位的对象数组。 在我的应用程序的某些时候,数组中的对象需要通知其他非数组对象的位置。 我明白,NSNotification是最好的方法,但我无法find一个像“发件人”和“收件人”体面的例子作为用户信息包装和解开CGPoint的通知。 谁能帮忙?

在cocoa触摸(而不是cocoa),CGPoints可以打包和解包

+ (NSValue *)valueWithCGPoint:(CGPoint)point - (CGPoint)CGPointValue 

NSValues可以存储在作为userinfoparameter passing的NSDictionary中。

例如:

 NSValue* value = [NSValue valueWithCGPoint:mypoint]; NSDictionary* dict = [NSDictionary dictionaryWithObject:value forKey:@"mypoint"]; 

并在您的通知:

 NSValue* value = [dict objectForKey:@"mypoint"]; CGPoint newpoint = [value CGPointValue]; 

与通知一起传递的userinfo对象只是一个NSDictionary。 在用户信息中传递CGPoint最简单的方法可能是使用-numberWithFloat:将X和Y坐标包装到NSNumbers中。 然后,您可以使用Xpos和Ypos作为键,在userinfo字典上使用setObject:forKey:例如。

你可能可以把它包装成NSMutableDictionary的一个很好的类别,使用setFloat:forKey之类的方法。