Objective-C中@synthesize合成变量名以及使用方法
来源:互联网 发布:ubuntu rm删除多个 编辑:程序博客网 时间:2024/06/16 10:51
1、Person.h
#import <Foundation/Foundation.h>@interface Person:NSObject@property (nonatomic, copy) NSString* name;-(id) initWithName:(NSString*) name;-(void) info;@end
2、Person.m
#import "Person.h"@implementation Person@synthesize name = _sname; //设置系统合成的属性名为_sname,这个可以是任意合法变量名-(id) initWithName:(NSString *)name{ if(self = [super init]) { self.name = name; //这其实是通过setName方法设置的 //self->_sname = name; //这是直接设置变量 } return self;}-(void) info{ NSLog(@"此人名为:%@",self.name);}-(void) setName:(NSString *)name{ NSLog(@"test"); self->_sname = name;}-(NSString*) description{ return [NSString stringWithFormat:@"<Person[_sname=%@]>",self->_sname];}@end3、PersonTest.m
#import "Person.h"int main(int argc, char* argv[]){ @autoreleasepool { Person* p = [[Person alloc] initWithName:@"a"]; NSLog(@"%@",[p description]); }}
阅读全文
0 0
- Objective-C中@synthesize合成变量名以及使用方法
- objective-c中 外部变量的使用方法
- 详解Objective-C中静态变量使用方法
- Objective-C中@property与@synthesize
- Objective-C中@property和@synthesize的简要说明
- Objective-C中@property和@synthesize的简要说明
- Objective-C 中@synthesize 和 @property 的用法
- Objective-C中@property与@synthesize配对使用
- Objective-C中@property和@synthesize的用法
- Objective-C @property & @synthesize 使用
- Objective-c @property和@Synthesize
- Objective-C - @property与@synthesize
- OutMan——Objective-C中成员变量的作用域、@property和@synthesize介绍和使用、构造方法和自定义构造方法
- objective-c--- 成员变量作用域、@property、@Synthesize、id、重写,自定义构造方法
- Objective-C—self 、super、点语法、成员变量的作用域、@property和@synthesize、id
- 【Objective-C学习笔记】核心语法——实例变量作用域、关键字@property和@synthesize
- Objective-C中获取类名
- Objective-C中获取类名
- 河南省第十届ACM省赛题目:问题 I: Transmit information
- SpringMVC学习笔记
- 配置python的virtualenv环境--macOS
- RxJava零基础入门(三)
- Linux守护进程.
- Objective-C中@synthesize合成变量名以及使用方法
- PAT乙级 ——1001. 害死人不偿命的(3n+1)猜想 (15)
- IP地址分类
- LeetCode:64. Minimum Path Sum
- jsp内置对象
- APP开发实战175-针对Android7.0及更高版本的后台优化方案
- Handler消息追踪和源码解析
- leveldb
- 史上最简单更新修复grub的方法