我想知道可可的不同风格的枚举声明背后的理由是什么?
像这样:
enum { constants.. }; typedef NSUInteger sometype;
Run Code Online (Sandbox Code Playgroud)
是否有理由使用typedef来获取NSUInteger的分配而不进行强制转换?
有时typedef是NSInteger/NSUInteger,为什么不总是使用NSInteger?使用NSUInteger真的有好处吗?
枚举标记名有时仍然使用,就像这里的_NSByteOrder.
这个答案也非常有用:Objective-C中的typedef枚举是什么?.
是否在UI更新事件之前处理了NSNotificationCenter postNotificationName发布的事件?
我需要知道,否则我的当前程序会在极少数情况下崩溃.
型号代码:
- (void)searchFinishedWithResults:(Results *)results {
self.results = results;
// If some table cells are loaded NOW, before notication is processed, we might crash!
[[NSNotificationCenter defaultCenter]
postNotificationName:SearchResultArrived object:nil];
}
Run Code Online (Sandbox Code Playgroud)
处理通知时,我将运行UITableView reloadData.
但是,请考虑在处理通知之前,是否必须更新UI.在这种情况下,-tableView:cellForRowAtIndexPath:将调用indexPath,但结果对象已更改,它将获取旧数据.