OC property(声明)】的更多相关文章

@interface Student : NSObject { int _age; int _no; float _height; } // 当编译器遇到@property时,会自动展开成getter和setter的声明 @property int age; //- (void)setAge:(int)newAge; //- (int)age; @property int no; //- (void)setNo:(int)newNo; //- (int)no; @property float h…
一:@property 后面可以有哪些修饰符? 1:线程安全的: atomic,nonatomic 2:访问权限的 readonly,readwrite 3:内存管理(ARC) assign, copy, strong,weak, 4: 内存管理(MRC) assign,retain,copy ARC 下,不显式指定任何属性关键字时,默认的关键字都有哪些? 基本数据: atomic,readwrite,assign 普通的 OC 对象: atomic,readwrite,strong 二. re…
因为父类指针可以指向子类对象,使用 copy 的目的是为了让本对象的属性不受外界影响,使用 copy 无论给我传入是一个可变对象还是不可对象,我本身持有的就是一个不可变的副本. 如果我们使用是 strong ,那么这个属性就有可能指向一个可变对象,如果这个可变对象在外部被修改了,那么会影响该属性. copy 此特质所表达的所属关系与 strong 类似.然而设置方法并不保留新值,而是将其“拷贝” (copy). 当属性类型为 NSString 时,经常用此特质来保护其封装性,因为传递给设置方法的…
文顶顶   OC语言@property @synthesize和id OC语言@property @synthesize和id 一.@property @synthesize关键字 注意:这两个关键字是编译器特性,让xcode可以自动生成getter和setter的声明和实现. (一)@property 关键字 @property 关键字可以自动生成某个成员变量的setter和getter方法的声明 @property int age; 编译时遇到这一行,则自动扩展成下面两句: - (void)…
@protocol Study; int main(int argc, const char * argv[]) { @autoreleasepool { Student *stu = [[[Student alloc] init] autorelease]; // 注意:OC是弱语法的,对类型要求不严格 // NSString *stu = [[[Student alloc] init] autorelease]; // [stu stringByAbbreviatingWithTildeIn…
.h文件 @interface NewClassName:ParentClassName { 实例变量://基本类型和指针类型  不能在这里初始化,系统默认会初始化 系统初始化遵循: 实例变量类型  默认值 Byte 0 short 0 int  0 long 0L char    \u0000' float 0.0F double 0.0D Boolean FALSE pointer   nil ~~~~ } 方法的声明: ~~~~ - (void) method: (int) argumen…
@property(copy,nonatomic)NSMutableString*copyStr; @property(strong,nonatomic)NSMutableString*strongStr; @property(weak,nonatomic)NSMutableString*weakStr; @property(assign,nonatomic)NSMutableString*assignStr; NSMutableString* originStr = [[NSMutableSt…
#import "Button.h" typedef int (^MySum) (int, int); void test() { // 定义了一个block,这个block返回值是int类型,接收两个int类型的参数 int (^Sum) (int, int) = ^(int a, int b) { return a + b; }; ,); NSLog(@"%i", a); } void test2() { // __block有2个下划线 __block ; /…
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…