swift 中"+"方法,与"-"方法的定义

来源:互联网 发布:世纪游轮更名巨人网络 编辑:程序博客网 时间:2024/05/16 14:04

OC中+方法的定义: +方法可以直接用类名可调,不需要创建对象

+(BOOL)返回值类型

(NSString *)identityString 传入值类型


+ (BOOL)judgeIdentityStringValid:(NSString *)identityString;



swift  +放的使用  
-> CGFloat 返回值类型,
height()方法名,()中为所传的参数 使用:

例如: tableView: UITableView  tableView对象名字,UITableView为类名


public staticfunc height() -> CGFloat{

    return0.3*kScreenWidth

}


OC中的-方法:-方法 由对象,和本类可调
-(BOOL) 返回值类型,
(NSDictionary *)dic 参数类型

-(BOOL)returnData:(NSDictionary *)dic;


swift中的-方法 

func name(parameters) -> return type {

   function body

}

name :为方法名,
parameters:为参数名
type:为返回值类型
function body:为你要处理的方式