2017年5月24日

OC Copy and MutableCopy的使用

摘要: #import @interface Student : NSObject // copy代表set方法会release旧对象、copy新对象 // 修改外面的变量,并不会影响到内部的成员变量 // 建议:NSString一般用copy策略,其他对象一般用retain @property (nonatomic, copy) NSString *name; + (id)studentWi... 阅读全文

posted @ 2017-05-24 22:43 守望星空 阅读(148) 评论(0) 推荐(0)

OC NSMutableArray

摘要: #import #import "Student.h" void arrayCreate() { NSMutableArray *array = [NSMutableArray arrayWithObject:@"1"]; // 添加元素 [array addObject:@"2"]; [array addObject:@"3"]; //... 阅读全文

posted @ 2017-05-24 22:32 守望星空 阅读(185) 评论(0) 推荐(0)

OC NSArray使用

摘要: #import #import "Student.h" #pragma mark 创建一个数组 void arrayCreate() { // 创建一个空的数组 NSArray *array = [NSArray array]; // 创建有1个元素的数组 array = [NSArray arrayWithObject:@"123"]; ... 阅读全文

posted @ 2017-05-24 22:31 守望星空 阅读(2782) 评论(0) 推荐(0)

OC NSMutableString的使用

摘要: #pragma mark 可变字符串的创建 void stringCreate() { // 预先分配10个字数的存储空间 NSMutableString *str = [[NSMutableString alloc] initWithCapacity:10]; // 设置字符串内容 [str setString:@"1234"]; // 拼... 阅读全文

posted @ 2017-05-24 17:28 守望星空 阅读(158) 评论(0) 推荐(0)

OC 指向指针的指针

摘要: #import void changeC(char *d) { *d = 9; } void changeStr(NSString **str2) { *str2 = @"123"; } int main(int argc, const char * argv[]) { @autoreleasepool { // char c = 10; //... 阅读全文

posted @ 2017-05-24 17:23 守望星空 阅读(129) 评论(0) 推荐(0)

OC Nsstring的使用

摘要: NSstring的其它用法 阅读全文

posted @ 2017-05-24 17:21 守望星空 阅读(115) 评论(0) 推荐(0)

OC 成员变量 ( -> 使用 )

摘要: @interface Student : NSObject { // @public // @protected // @private // 默认的作用域是@protected int age; @protected int no; @public float height; } @propert... 阅读全文

posted @ 2017-05-24 17:13 守望星空 阅读(176) 评论(0) 推荐(0)

OC @protocol(声明协议 )

摘要: 调用 阅读全文

posted @ 2017-05-24 17:10 守望星空 阅读(251) 评论(0) 推荐(0)

OC property(声明)

摘要: // 在xcode4.5的环境下,可以省略@synthesize,并且默认会去访问_age这个成员变量// 如果找不到_age这个成员变量,会自动生成一个叫做_age的私有成员变量 阅读全文

posted @ 2017-05-24 17:07 守望星空 阅读(142) 评论(0) 推荐(0)

OC category(分类)

摘要: // ()代表着是一个分类 // ()中的Test代表着分类的名称 @interface Student (Test) // 分类只能扩展方法,不能增加成员变量 - (void)test2; @end 阅读全文

posted @ 2017-05-24 17:03 守望星空 阅读(107) 评论(0) 推荐(0)

OC block声明和使用

摘要: 补充: 阅读全文

posted @ 2017-05-24 17:02 守望星空 阅读(371) 评论(0) 推荐(0)

OC 内存管理(retain和release)

摘要: 内存管理 retain和release简单使用 #import <Foundation/Foundation.h> #import "Student.h" void test() { Student *stu = [[Student alloc] init]; // 1 // z代表无符号 NSLo 阅读全文

posted @ 2017-05-24 16:50 守望星空 阅读(361) 评论(0) 推荐(0)

OC @class关键字

摘要: // 如果是继承某个类,就要导入类的头文件// 如果只是定义成员变量、属性,用@class 阅读全文

posted @ 2017-05-24 16:47 守望星空 阅读(158) 评论(0) 推荐(0)

OC typedef(起别名)

摘要: // #define Integer int // 给基本数据类型起别名 void test() { typedef int Integer; typedef Integer MyInteger; typedef unsigned int UInteger; int a = 10; Integer b = 9; ... 阅读全文

posted @ 2017-05-24 16:44 守望星空 阅读(1047) 评论(0) 推荐(0)

OC static 和函数

摘要: #include // 定义一个one函数 // 完整地定义一个外部函数需要extern关键字 //extern void one() { // printf("调用了one函数\n"); //} // 内部函数,需要用static关键字修饰,说明不能在其他文件中访问 static void one() { printf("调用了one函数\n"); } #ifnde... 阅读全文

posted @ 2017-05-24 16:42 守望星空 阅读(218) 评论(0) 推荐(0)

OC static 和变量

摘要: 调用: 阅读全文

posted @ 2017-05-24 16:40 守望星空 阅读(155) 评论(0) 推荐(0)

OC 类 的声明

摘要: Student.h 阅读全文

posted @ 2017-05-24 16:37 守望星空 阅读(180) 评论(0) 推荐(0)

OC extern和函数

摘要: #include // 定义一个one函数 // 完整地定义一个外部函数需要extern关键字 //extern void one() { // printf("调用了one函数\n"); //} // 默认情况下就是外部函数,所以可以省略extern void one() { printf("调用了one函数\n"); } #ifndef extern___... 阅读全文

posted @ 2017-05-24 16:33 守望星空 阅读(240) 评论(0) 推荐(0)

OC extern和变量

摘要: 注意: extern只能用来声明全部变量,不能拿来定义变量 阅读全文

posted @ 2017-05-24 16:31 守望星空 阅读(177) 评论(0) 推荐(0)

OC 枚举

摘要: void test() { // 定义一种枚举类型 enum Season {spring, summer, autumn, winter}; // 定义一个枚举变量s enum Season s = winter; } void test1() { // 定义枚举类型的同时定义一个枚举变量s enum Season {spring... 阅读全文

posted @ 2017-05-24 16:28 守望星空 阅读(122) 评论(0) 推荐(0)

OC 结构体

摘要: void test() { // 这个机构只能在函数内部使用 // 定义一个名为Student的结构体类型 struct Student { int age; // 年龄 char *name; // 姓名 float height; // 身高 }; // 定义一个结构体变量 struct... 阅读全文

posted @ 2017-05-24 16:27 守望星空 阅读(287) 评论(0) 推荐(0)

OC 构造方法

摘要: #import @interface Student : NSObject { int _age; int _no; } - (void)setAge:(int)age; - (int)age; - (void)setNo:(int)no; - (int)no; // 自己写一个构造方法 - (id)initWithAge:(int)age andNo:(int)n... 阅读全文

posted @ 2017-05-24 16:25 守望星空 阅读(167) 评论(0) 推荐(0)

OC 方法声明使用

摘要: Person.h Person.m 阅读全文

posted @ 2017-05-24 16:23 守望星空 阅读(160) 评论(0) 推荐(0)

C语言 变量类型

摘要: // a是一个全局变量,静态变量 int a; void test() { // b是一个局部变量,自动变量 int b = 0; b++; // c是一个局部变量,静态变量 static int c = 0; c++; printf("b=%d, c=%d\n", b, c); } int main(int a... 阅读全文

posted @ 2017-05-24 16:16 守望星空 阅读(188) 评论(0) 推荐(0)

C语言 字符串处理函数

摘要: #include #include // strlen void test() { // 测量字符串常量的字符长度(不包括\0这个字符) int len = strlen("李某某"); //printf("%d\n", len); // 测量字符串变量的字符长度 char s[] = "lmj"; //printf("%d\... 阅读全文

posted @ 2017-05-24 16:15 守望星空 阅读(187) 评论(0) 推荐(0)

C语言 Include指令(引用头文件)

摘要: #include "one.h" #include "two.h" int main(int argc, const char * argv[]) { one(); two(); return 0; } 阅读全文

posted @ 2017-05-24 16:13 守望星空 阅读(730) 评论(0) 推荐(0)

C语言 字符串的声明与使用

摘要: // 字符串的定义和初始化 void test() { // "mj" char s[] = {'m', 'j', '\0'}; // 字符串"mj" char s1[3] = {'m', 'j', '\0'}; // 字符串"mj" char s2[3] = {'m', 'j'}; // 并不是正规的字符串 char s... 阅读全文

posted @ 2017-05-24 16:11 守望星空 阅读(7154) 评论(0) 推荐(0)

C语言 指针

摘要: 指针的基本声明: void test() { char a; // a = 10; 直接引用 // 定义了一个指针变量b,而且b只能指向char类型的变量 char *b; // 让指针变量b指向a b = &a; // 这里的*b代表:访问b值对应的存储空间(也就是变量a的存储空间) // 相当于 阅读全文

posted @ 2017-05-24 16:10 守望星空 阅读(190) 评论(0) 推荐(0)

C语言 指向函数的指针

摘要: #include int sum(int a, int b) { int c = a + b; printf("%d + %d = %d\n", a, b, c); return c; } int minus(int a, int b) { return a - b; } int mul(int a, int b) { ... 阅读全文

posted @ 2017-05-24 16:01 守望星空 阅读(170) 评论(0) 推荐(0)

C语言 条件编译(if )

摘要: #include #define NUM -1 int main(int argc, const char * argv[]) { #if NUM > 0 printf("NUM大于0"); #elif NUM == 0 printf("NUM等于0"); #else printf("NUM小于0"); #endif return... 阅读全文

posted @ 2017-05-24 16:00 守望星空 阅读(194) 评论(0) 推荐(0)

C语言 数组的使用

摘要: #include // 数组的定义和存储 void test1() { int ages[5]; // 64bit环境下占用4*5=20个字节 // 计算数组占据的存储空间 // size_t size = sizeof(ages); //printf("ages占据的字节:%d", size); // 查看数组的地址 ... 阅读全文

posted @ 2017-05-24 15:59 守望星空 阅读(391) 评论(0) 推荐(0)

C语言 宏的定义

摘要: #include // NUM叫做宏名 // 6是用来替换宏名的字符串 #define NUM 6 #define mul(a, b) ((a)*(b)) void test() { // 双引号中的NUM并不会被替换为6 char *s = "NUMBER"; int a[NUM] = {1,2,3,4,5,6}; ... 阅读全文

posted @ 2017-05-24 15:58 守望星空 阅读(131) 评论(0) 推荐(0)

C语言 返回指针的函数

摘要: #include char * test() { return "itcast"; } int main(int argc, const char * argv[]) { printf("%s", test()); return 0; } 阅读全文

posted @ 2017-05-24 15:57 守望星空 阅读(179) 评论(0) 推荐(0)

C语言 scanf函数

摘要: #include void test1() { // 1.提示用户输入数据 printf("请输入一个整数:"); // 2.接收用户输入的数据 int a; // &a代表变量a的地址 // 输入完毕后敲回车 scanf("%d", &a); // 3.计算a的平方 printf("%d的平方为:%... 阅读全文

posted @ 2017-05-24 15:56 守望星空 阅读(173) 评论(0) 推荐(0)

C语言 Printf函数

摘要: #include int main(int argc, const char * argv[]) { // insert code here... printf("Hello, World!\n"); printf("My age is %d\n", 26); // My age is 26,height is... 阅读全文

posted @ 2017-05-24 15:54 守望星空 阅读(149) 评论(0) 推荐(0)

导航