iOS开发常用的方法收集整理

1.全局tableView分割线左右对齐
//设置全局cell分割线与屏幕等宽
[[UITableView appearance] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[[UITableView appearance] setSeparatorInset:UIEdgeInsetsZero];
[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsZero];

if ([UITableView instancesRespondToSelector:@selector(setLayoutMargins:)]) {
    [[UITableView appearance] setLayoutMargins:UIEdgeInsetsZero];
    [[UITableViewCell appearance] setLayoutMargins:UIEdgeInsetsZero];
    [[UITableViewCell appearance] setPreservesSuperviewLayoutMargins:NO];
}

2.强引用或者弱引用
/**
Synthsize a weak or strong reference.

Example:
@weakify(self)
[self doSomething^{
@strongify(self)
if (!self) return;
...
}];

*/

ifndef weakify

#if DEBUG
    #if __has_feature(objc_arc)
    #define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;
    #else
    #define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
    #endif
#else
    #if __has_feature(objc_arc)
    #define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
    #else
    #define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
    #endif
#endif

endif

ifndef strongify

#if DEBUG
    #if __has_feature(objc_arc)
    #define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
    #else
    #define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;
    #endif
#else
    #if __has_feature(objc_arc)
    #define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;
    #else
    #define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;
    #endif
#endif

endif

3.处理编译器警告

pragma clang diagnostic push

pragma clang diagnostic ignored "-相关命令"

// 你自己的代码

pragma clang diagnostic pop

常用命令: "-Wdeprecated-declarations" ->方法弃用告警
"-Wincompatible-pointer-types" ->不兼容指针类型
"-Wunused-variable" ->未使用变量

4.方法弃用
DEPRECATED_ATTRIBUTE
DEPRECATED_MSG_ATTRIBUTE(msg)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在深寂的夜中大声沉默 在光明的风里饮酒高歌 被狂风吹散了假装的欢乐 雪藏心底的忧伤浮现 像烈火中蕴藏千年刺骨的寒 ...
    感激不尽阅读 244评论 4 4
  • (稻盛哲学学习会)打卡第 39 天 姓名:王有光 部门:分水碶 组别:待定 【知~学习】 诵读《活法》第四章 以利...
    王有光阅读 137评论 0 0
  • 先贴一组数据: 根据这些数据可以看到, 唯品会的月活、日活、日使用次数和使用时长非常可观,虽然有闪购模式的特殊原因...
    李渡阅读 1,563评论 4 3
  • 1 假如这本书可以启发大家开始写 “ 晨间日记 ” 的话 , 实在是一件令人非常开心的事情 。只要您开始写 “ 晨...
    符永宁阅读 156评论 0 0
  • 写作表达要言之有物,言之有理。言之有物,就是写的内容要注意表达力,要注意用词遣字,要善用成语,要有佳句,只有这样才...
    思码读高效学习法阅读 2,232评论 0 1