好的 iOS 代码习惯

时间:2024-03-26 22:35:44

一,使用别人的框架时,尽量在退出时移除框架创建的对象

     if (_giftToastView) {
[_giftToastView removeFromSuperview];
_giftToastView = nil;
}

二,在当前类写网络请求时,勿忘设置当前类是网络请求类的代理.

         [[[GetAppDelegate taskManager]timeTaskDataMgr]reloadData];
[[GetAppDelegate taskManager]timeTaskDataMgr].delegate = self;

三,接收到的服务器数据不要直接处理,应该先判断一番

     EnumTaskState state = TaskStateUndefine;
NSInteger num = [_state integerValue];
if (num == ) {
state = TaskStateInProgress;
} else if (num == ) {
state = TaskStatewillDone;
} else if (num == ) {
state = TaskStatedidDone;
}

四,