OC 方法声明使用
2024-09-22 05:05:43
Person.h
#import <Foundation/Foundation.h> @interface Person : NSObject {
int _age;
} - (void)setAge:(int)age; // 方法名是setAge:
- (int)age; // 方法名是age // 方法名是setAge:andNo:
// - (void)setAge:(int)newAge andNo:(int)no;
@end
Person.m
#import "Person.h" @implementation Person - (void)setAge:(int)age {
NSLog(@"调用了setAge方法:%i", age);
_age = age; // 这是错误的写法,会导致死循环,无限调用set方法
// self.age = newAge;// [self setAge:newAge];
} - (int)age {
NSLog(@"调用了age方法:%i", _age); return _age;
}
@end
最新文章
- 第一个python实例--监控cpu
- PreparedStatement
- 关于UltraEdit的两个小问题
- 如何加载JS
- require
- MySQL到MsSQL的迁移工具——SSMA
- 云计算之路-阿里云上:遭遇CDN问题
- UVA5870 乱搞 Smooth Visualization
- mysql命令行导入sql文件
- 【Convert Sorted List to Binary Search Tree】cpp
- $(document).Ready()方法 VS OnLoad事件 VS $(window).load()方法
- hdu4081
- 20. Valid Parentheses【leetcode】
- Xcode中StoryBoard Reference 新特性的使用
- Vue.js实现注册功能
- sqlsever存储过程配合代理作业自动定时建表
- Java开发笔记(五十九)Java8之后的扩展接口
- Hdoj 1850.Being a Good Boy in Spring Festival 题解
- Realm 处理List<;String>; 问题 Type parameter &#39;java.lang.String&#39; is not within its bound; should implement &#39;io.realm.RealmModel
- ansible运维工具(一)
热门文章
- PIE SDK矢量数据编辑事件的监听
- 转 .net 获取IP地址的三个方法的比较
- RedisClient 连接redis 提示 ERR Client sent AUTH, but no password is set
- Maven---pom.xml 详解(转)
- 啊啊啊啊啊啊啊今天就写,炒鸡简单 数据库Sqlite的创建,库的增删改查
- 《HTTP权威指南》之HTTP连接管理及对TCP性能的考虑
- 【原】shell编写一个简单的jmeter自动化压测脚本
- OpenLayers 案例一
- NDK编译不同架构的参数
- 深入理解Javascript封装DOMContentLoaded事件