摘要:#import @interface Student : NSObject // copy代表set方法会release旧对象、copy新对象 // 修改外面的变量,并不会影响到内部的成员变量 // 建议:NSString一般用copy策略,其他对象一般用retain @property (nonatomic, copy) NSString *name; + (id)studentWi...
阅读全文
摘要:#import #import "Student.h" void arrayCreate() { NSMutableArray *array = [NSMutableArray arrayWithObject:@"1"]; // 添加元素 [array addObject:@"2"]; [array addObject:@"3"]; //...
阅读全文
摘要:#import #import "Student.h" #pragma mark 创建一个数组 void arrayCreate() { // 创建一个空的数组 NSArray *array = [NSArray array]; // 创建有1个元素的数组 array = [NSArray arrayWithObject:@"123"]; ...
阅读全文
摘要:#pragma mark 可变字符串的创建 void stringCreate() { // 预先分配10个字数的存储空间 NSMutableString *str = [[NSMutableString alloc] initWithCapacity:10]; // 设置字符串内容 [str setString:@"1234"]; // 拼...
阅读全文
摘要:#import void changeC(char *d) { *d = 9; } void changeStr(NSString **str2) { *str2 = @"123"; } int main(int argc, const char * argv[]) { @autoreleasepool { // char c = 10; //...
阅读全文
摘要:@interface Student : NSObject { // @public // @protected // @private // 默认的作用域是@protected int age; @protected int no; @public float height; } @propert...
阅读全文
摘要:// 在xcode4.5的环境下,可以省略@synthesize,并且默认会去访问_age这个成员变量// 如果找不到_age这个成员变量,会自动生成一个叫做_age的私有成员变量
阅读全文
摘要:// ()代表着是一个分类 // ()中的Test代表着分类的名称 @interface Student (Test) // 分类只能扩展方法,不能增加成员变量 - (void)test2; @end
阅读全文
摘要:内存管理 retain和release简单使用 #import <Foundation/Foundation.h> #import "Student.h" void test() { Student *stu = [[Student alloc] init]; // 1 // z代表无符号 NSLo
阅读全文
摘要:// 如果是继承某个类,就要导入类的头文件// 如果只是定义成员变量、属性,用@class
阅读全文
摘要:// #define Integer int // 给基本数据类型起别名 void test() { typedef int Integer; typedef Integer MyInteger; typedef unsigned int UInteger; int a = 10; Integer b = 9; ...
阅读全文
摘要:#include // 定义一个one函数 // 完整地定义一个外部函数需要extern关键字 //extern void one() { // printf("调用了one函数\n"); //} // 内部函数,需要用static关键字修饰,说明不能在其他文件中访问 static void one() { printf("调用了one函数\n"); } #ifnde...
阅读全文
摘要:#include // 定义一个one函数 // 完整地定义一个外部函数需要extern关键字 //extern void one() { // printf("调用了one函数\n"); //} // 默认情况下就是外部函数,所以可以省略extern void one() { printf("调用了one函数\n"); } #ifndef extern___...
阅读全文
摘要:注意: extern只能用来声明全部变量,不能拿来定义变量
阅读全文
摘要:void test() { // 定义一种枚举类型 enum Season {spring, summer, autumn, winter}; // 定义一个枚举变量s enum Season s = winter; } void test1() { // 定义枚举类型的同时定义一个枚举变量s enum Season {spring...
阅读全文