程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

Xcode12.5的自定义代码块的使用和函数注释(学会事半功倍)

发布于2021-06-07 20:49     阅读(1021)     评论(0)     点赞(23)     收藏(0)


Xcode12.5的自定义代码块的使用和函数注释(学会事半功倍)

第一篇 快捷键的定义

@property (nonatomic , strong) <#type#> <#name#>

xcode 6,7,8版本,可以拖动到代码段,在里面更改<#type#> <#name#>,当我输入这些,直接跳到其他地方了。xcode12.5必须在编辑区域就要弄好。这样按tab键才有用。

选中上面代码,右键找到create code snippet ,
然后自己定义快捷键,编程语言作用范围,以及自定义代码段的名称等。具体看我另外一篇博客详解。
NSLog(@"");这样的函数都要定义成代码块,快捷键设为nslog小写,快捷键自己喜好添加。简明扼要,见名之意。常用十五大代码块如下,以及我自己定义的快捷键都分享一下。

  1. 打印函数的封装 快捷键 nslog
NSLog(@"<#name#>")

Swift项目中 打印函数 快捷键deprin

debugPrint("<#String#>")

1 关于定义字符串属性的oc代码段,使用nonatomic和copy修饰的,非原子属性,快捷键pcopy

@property (nonatomic,copy) NSString *<#string#>;

2.快捷键pStrong, 定义强引用属性相关的,例如NSArray,NSDictionary,模型,

@property (nonatomic,strong) <#Class#> *<#object#>;

3.快捷键pweak,弱引用相关属性

@property (nonatomic,weak) <#Class#> *<#object#>;

4.快捷键passign,常量相关的 CGFloat ,CGRect,CGPoint,int,double,float,NSInteger,等

@property (nonatomic,assign) <#Class#> <#property#>;

5.快捷键pdelegate,代理的属性封装

@property (nonatomic,weak) id<<#protocol#>> <#delegate#>;

6.快捷键pblock

@property (nonatomic,copy) <#Block#> <#block#>;

7.快捷键mark

#pragma mark <#mark#>

8.快捷键underlinemark:

#pragma mark - <#gmark#>

9.快捷键userUITableViewCell

static NSString *ID=@"Cell";
<#Class#> *cell=[tableView dequeueReusableCellWithIdentifier:ID];
if(cell==nil){
  cell=[[<#Class#> alloc] initWithStyle:UITableViewCellStyleDefault      reuseIdentifier:ID];
}
return cell;

10.快捷键initObj

if(self=[super init]){
    <#init#>
}
return self;

11.快捷键dataFil

-(void)dataFill:(<#ModelClass#> *)<#model#>{
    <#code#>
}

12.快捷键MainGCD

dispatch_async(dispatch_get_main_queue(), ^{
<#code#>
});

13.快捷键GlobalGCD

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
<#code#>
});

14.快捷键AfterGCD

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<#delayInSeconds#> * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
<#code to be executed after a specified delay#>
});

15.快捷键OnceGCD (写单例的)

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
<#code to be executed once#>
});

第二篇 Swift和OC项目的注释,方法的声明等使用

OC注释

#pragma mark - 数据源方法

格式写对了,上面自动出来一条横线,否则格式有问题。
在这里插入图片描述

swift注释

// MARK: - 数据源方法的实现

tab键盘 table几次,跟函数名对齐。不要顶在最前面。
格式写对了,上面自动出来一条横线,否则格式有问题。

在这里插入图片描述

非常重要
在swift和oc函数,光标处在上面,按下command + option + / 可以自动弹出方法的描述,返回值说明,参数说明等。原先是github一个项目,后来被苹果收购了,上面还有goodbye的语句等,叫什么vvdocuemnt。
例如:

    /// 加法函数
    /// - Parameter a: 变量a
    /// - Returns: 累加和
    func addNum(a: Int) -> Int {
        let c: Int = a + 10
        debugPrint("asd")
        return c
    }

oc写法

/// 测试函数
/// @param text 传人图片名称字符串
/// @param imgView 图像
-(void)demo:(NSString *)text WithImageView:(UIImageView *) imgView{
    imgView.image = [UIImage imageNamed:text];
}

原文链接:https://blog.csdn.net/A1521315qwss/article/details/117520730



所属网站分类: 技术文章 > 博客

作者:你看我迷人不

链接:http://www.phpheidong.com/blog/article/89460/bb1ccc02204f2be199dc/

来源:php黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

23 0
收藏该文
已收藏

评论内容:(最多支持255个字符)