selector

IOS Static inline 函数

2020-12-04  本文已影响0人  沙人Q
  1. 内联函数只是我们向编译器提供的申请,编译器不一定采取inline形式调用函数.
  2. 内联函数不能承载大量的代码.如果内联函数的函数体过大,编译器会自动放弃内联.
  3. 内联函数内不允许使用循环语句或开关语句.
  4. 内联函数的定义须在调用之前.

备注 : 个人笔记 需验证一下

例如:

static inline CGFloat GetViewHeight(UIView *view) {
    return view.frame.size.height;
}

//获取底部安全距离
static inline CGFloat ZL_SafeAreaBottom() {
    CGFloat temp = 0;
    if (@available(iOS 11.0, *)) {
        temp = UIApplication.sharedApplication.keyWindow.safeAreaInsets.bottom;
    }
    return temp;
}
static inline UIImage * GetImageWithName(NSString *name) { 
    return [UIImage imageNamed:name];
}
上一篇 下一篇

猜你喜欢

热点阅读