【Objective

编程入门 行业动态 更新时间:2024-10-23 19:24:21

【<a href=https://www.elefans.com/category/jswz/34/1766122.html style=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

更多推荐

【Objective

本文发布于:2023-11-15 21:32:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606685.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Objective

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!