我有一个复杂的C结构,很难将这个结构一一转换为NSDictionary。 如何通过 NSNotificationCenter 发布此 C 结构并从 NSNotificationCenter 回调函数中检索它? 任何建议将不胜感激,谢谢!
最佳答案
以 NSValue 形式存储和检索
商店:
CustomStruct instanceOfCustomStruct = ...;
NSValue * valueOfStruct = [NSValue valueWithBytes:&instanceOfCustomStruct objCType:@encode(CustomStruct)];
[[NSNotificationCenter defaultCenter] postNotificationName:@"YourNotification" object:self userInfo:@{@"CustomStructValue" : valueOfStruct}];
检索:
NSValue * valueOfStruct = note.userInfo[@"CustomStructValue"];
CustomStruct instanceOfCustomStruct;
[valueOfStruct getValue:&instanceOfCustomStruct];
关于ios - NSNotificationCenter 发布 C 结构并从通知回调函数中检索它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23283823/