美文网首页
重要的代码片段

重要的代码片段

作者: 小马飞驰bnb | 来源:发表于2016-04-12 15:48 被阅读65次

objc中标识类、方法或属性过期宏

DEPRECATED_ATTRIBUTE

DEPRECATED_ATTRIBUTE
/// apns路由器
@interface XTXMessageRouter : NSObject
- (id)init __attribute__((unavailable("init not available, call initWithUrl: instead")));
/// 初始化
- (instancetype)initWithUrl:(NSString *)urlStr;
/// 执行跳转
- (void)go DEPRECATED_ATTRIBUTE;

updateViewConstraints

此函数是从iOS6.0开始在ViewController中新增一个更新约束布局的方法,这个方法默认的实现是调用对应View的 updateConstraints 。ViewController的View在更新视图布局时,会先调用ViewController的updateViewConstraints 方法。我们可以通过重写这个方法去更新当前****View****的内部布局,而不用再继承这个****View****去重写****-updateConstraints****方法。我们在重写这个方法时,务必要调用**** super ****或者**** ****调用当前****View****的**** -updateConstraints ****方法。

controller :

#pragma mark - system
- (void)updateViewConstraints {

    WS(weakSelf)

    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.edges.equalTo(weakSelf.view);
    }];

    [super updateViewConstraints];
}

view :

- (void)updateConstraints {

    WS(weakSelf)
    [self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.edges.equalTo(weakSelf);
    }];
    [super updateConstraints];
}

dispatch_main_async_safe

注意这里判断的是队列而不是线程

#ifndef dispatch_main_async_safe
#define dispatch_main_async_safe(block)\
    if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {\
        block();\
    } else {\
        dispatch_async(dispatch_get_main_queue(), block);\
    }
#endif

相关文章

  • 重要的代码片段

    objc中标识类、方法或属性过期宏 DEPRECATED_ATTRIBUTE updateViewConstrai...

  • Xcode代码块

    代码片段 Xcode的代码片段(Code Snippets)创建自定义的代码片段,当你重用这些代码片段时,会给你带...

  • 2.4 系统主界面的制作

    2.4.1主界面的功能系统结构图对应 2.4.5 重要代码片段

  • Fast Prime List Functions的代码

    把写代码过程中比较重要的代码片段珍藏起来,下边资料是关于Fast Prime List Functions的代码。...

  • vscode 代码片段设置

    文件-首选项-用户片段 选择新建代码片段 打印代码片段

  • 代码片段&编程小技巧

    代码片段大全代码片段,代码分享,PHP代码分享,Java代码分享,Ruby代码分享,Python代码分享,HTML...

  • 代码片段

    消除table中的th除去了所有border,margin,padding之后还是会有间隙的问题 移动端必须加的代...

  • 代码片段

    简介: 关于代码片段,网上已经有很多资料了,这里主要介绍下结合zyApi如何快速的写出请求模版。 实现: 上面三份...

  • 代码片段

    for循环和迭代器 在判断一个数组中是否包含某个值的时候,开发者经常这样做: 推荐使用for循环遍历的形式或者使用...

  • 代码片段

    单例模式 获取Keystore 证书指纹

网友评论

      本文标题:重要的代码片段

      本文链接:https://www.haomeiwen.com/subject/ffzblttx.html