最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

【Objective

运维笔记admin39浏览0评论

【Objective

【Objective

方法定义

参考:.html

Objective-C编程语言中方法定义的一般形式如下

- (return_type) method_name:( argumentType1 )argumentName1 joiningArgument2:( argumentType2 )argumentName2 ... joiningArgumentn:( argumentTypen )argumentNamen {body of the function
}

示例:

/* 返回两个参数的最大值 */
- (int) max:(int) num1 secondNumber:(int) num2 {/* 局部变量声明 */int result;if (num1 > num2) {result = num1;} else {result = num2;}return result; 
}

alloc 方法

OC中经常使用 NSObject *object = [[NSObject alloc] init]; 这行代码去创建一个对象

通过对alloc底层源码的分析, 可以了解到:
① alloc的主要目的是开辟内存空间;
② 主要的核心逻辑是 计算内存大小->申请内存空间->绑定isa;
③ 计算内存大小是按照16字节对齐的。

参考:.html

发布评论

评论列表(0)

  1. 暂无评论