IOS菜鸟学习

1.NS是系统库.
2.IOS类的声明:
@interface MyObject : NSObject {
    int memberVar1; // 实体变量
    id  memberVar2;
}

+(return_type) class_method; // 类方法

-(return_type) instance_method1; // 实例方法
-(return_type) instance_method2: (int) p1;
-(return_type) instance_method3: (int) p1 andPar: (int) p2;
@end

//+:代表类函数,不需要实例即可使用.同c++
    声明interface开始,end结束.
3.IOS字符串:
NSString* myString = @"My String\n";
NSString* anotherString = [NSString stringWithFormat:@"%d %s", 1, @"String"];

// 从一个C语言字符串创建Objective-C字符串
NSString*  fromCString = [NSString stringWithCString:"A C string"
encoding:NSASCIIStringEncoding];

@是一个助记符,通过助记符可以用常量字符串创建对象.

4.IOS类的实现
@implementation MyObject {
  int memberVar3; //私有實體變數
}

+(return_type) class_method {
    .... //method implementation
}
-(return_type) instance_method1 {
     ....
}
-(return_type) instance_method2: (int) p1 {
    ....
}
-(return_type) instance_method3: (int) p1 andPar: (int) p2 {
    ....
}
@end

implementation开始,end结束.

5.中括号的用法[类名 类方法]或[对象 实例方法]

[VLPAProxyhelper morePlayList:listDic]VLPAProxyhelper类名 morePlayList类方法 listDic参数

6.id是一个对象指针,可以转换为任何数据类型.不常用

猜你喜欢

转载自www.cnblogs.com/mcy0808/p/8986797.html