0
点赞
收藏
分享

微信扫一扫

AppCode 设置 getter 模板


-(UILabel *)toastLabel {
    if(!_toastLabel){
        _toastLabel = [[UILabel alloc] init];
        _toastLabel.text = @"验证码已经发送到+86";
        _toastLabel.font = [UIFont systemFontOfSize:12.0];
    }
    return _toastLabel;
}

这种代码基本上每次定义一个变量,都是需要的,那能不能根据定义的变量自动生成呢,至少要是这样

-(UILabel *)toastLabel {
    if(!_toastLabel){
        _toastLabel = [[UILabel alloc] init];
    }
    return _toastLabel;
}

在 appcode 中,定义变量后,利用 alt+回车 快捷键 -> 选择弹窗中的 Implement accessor methods -> 选择 toastLabel-> 自动生成了定义方法

- (UILabel *)toastLabel {
    return _toastLabel;
}

但是这不是我们想要的

1、点击 AppCode->选择 Preferences

AppCode 设置 getter 模板_自动生成


2、找到 File and Code Templates -> 选择code -> 找到 OC Property Getter Body

里面的代码是

#if ($IVAR_IS_AVAILABLE == "true")
return $IVAR;#else
return $DEFAULT_RETURN_VALUE;#end

AppCode 设置 getter 模板_appcode_02

修改成自己想要的代码模式

#if ($IVAR_IS_AVAILABLE == "true")
if(!$IVAR){
    $IVAR = [[$RETURN_TYPE.replace("*"," ") alloc]init];
}
return $IVAR;#else
return $DEFAULT_RETURN_VALUE;#end

最后再 alt+回车就生成自己想要的了

- (UILabel *)toastLabel {
    if (!_toastLabel) {
        _toastLabel = [[UILabel alloc] init];
    }
    return _toastLabel;
}


举报

相关推荐

0 条评论