标签:
#import <Foundation/Foundation.h>
#import "Article.h"
#import "Person.h"
int main(int argc, const char * argv[]) {
@autoreleasepool { //自动释放池 (半自动)
//-------------------------枚举类---------------------------------//
NSArray *parent = @[@"father",@"mother" ];
NSEnumerator *rator =[parent objectEnumerator]; //objectEnumerator 向数组请求这个枚举器
id object; //id 可以指向一切对象类型
while ((object = [rator nextObject])) //nextObject 下一个对象
{
NSLog( @"object : %@", object );
}
//---------------------------字典---------------------------------//
NSArray *PersonValue = @[ @"jabez",@"11",@"西安"];
NSArray *PersonKey = @[ @"name", @"age", @"location" ]; //第一种方法
NSDictionary *dict = [NSDictionary dictionaryWithObjects:PersonValue forKeys: PersonKey]; //定义一个不可变字典
NSLog( @"name : %@", dict[@"name"]);
NSLog( @"age : %@", dict[@"age"] );
NSLog( @"location : %@", dict[@"location"] );
NSDictionary *dict1 = @{
@"name" : @"jabez",
@"age" : @"18",
@"location" : @"西安"
}; //第二种方法
NSLog( @"location: %@ " , [dict1 objectForKey:@"location"] );
//-------------------------可变的字典------------------------// (重点)
NSArray *muDictKey = @[@"age", @"location"];
NSArray *muDictValue = @[ @"17", @"西安"];
//创建一个可变的字典 记住里面传值的数组 keyArray valueArray
NSMutableDictionary *dict2 = [NSMutableDictionary dictionaryWithObjects: muDictValue forKeys: muDictKey];
NSLog( @"age: %@", [dict2 objectForKey:@"age"] ); //输入某一个键的值
[dict2 setObject:@"16" forKey: @"age"]; //修改一个键对应的值
[dict2 setValue: @"15" forKey: @"age" ];
[dict2 addEntriesFromDictionary:@{@"name":@"jabez"}]; //新增一个键值对
[dict2 removeObjectForKey:@"age"]; //删除某一个键值对
[dict2 removeAllObjects]; //清空字典
NSLog( @"age: %@", [dict2 objectForKey:@"age"] );
NSLog( @"name: %@", [dict2 objectForKey:@"name"] );
//------------------结构体------------//
struct date{
int year;
int month;
int day;
};
struct date tDate = { .day = 2015};
NSLog( @"%i - %i - %i", tDate.year , tDate .month, tDate.day );
//--------------NSRange 截图字符串或数组范围--------------------//
NSRange range = NSMakeRange( 4, 2 );
NSString *str1 = @"abcdef";
NSLog( @"%@", [str1 substringWithRange:range]);
//---------------------CG类型----------------------//
//CGSize/NSSize 描述一个物体的高度与宽度 ( 宽度 , 高度 )
CGSize cgsize = NSMakeSize(10, 20);
NSLog( @"width is %.2f", cgsize.width );
NSLog( @"height is %.2f", cgsize.height );
//CGPoint/NSPoint 描述一个物体的坐标 ( 横坐标 , 纵坐标 )
CGPoint cgpoint = NSMakePoint(3, 1);
NSLog( @"cgpoint x is: %.2f", cgpoint.x );
NSLog( @"cgpoint y is: %.2f", cgpoint.y );
//CGRect/NSRect 描述一个物体的多维度信息
//( 坐标( origin.x , origin.y ) )
//( 高度与宽度( size.width , size.heigth ) )
CGRect cgrect = NSMakeRect(0, 0 , 0 , 0);
cgrect.origin = cgpoint; //赋值相关物体的坐标
cgrect.size = cgsize; //赋值相关物体的尺寸
NSLog( @"物体横坐标为:%.2f", cgrect.origin.x );
NSLog( @"物体纵坐标为:%.2f", cgrect.origin.y );
NSLog( @"物体高度为:%.2f", cgrect.size.height );
NSLog( @"物体宽度为:%.2f", cgrect.size.width );
//
NSDate *today = [NSDate date];
NSLog( @"%@", today );
//--------------NSNumber 封装基本的数据类型-----------------// (重点) NSNumber *number;
number = @123;
NSLog( @"%@", number);
number = @1.2f;
NSLog( @"%@", number); //打印的注意 此处因为是对象类型 所以用%@
//第二种写法 内置的numberWithInt\float\char...类方法
NSNumber *number1 = [NSNumber numberWithInt:10];
NSLog( @"%@", number1 );
//-----NSNull 用于在集合类型中空值的元素 如:斗地主已抽取的牌------//
NSNull *pc = [NSNull null];
NSMutableArray *nullArray = [NSMutableArray arrayWithObjects: @"123", pc, @"234", nil];
NSLog( @"%@", nullArray[0]);
NSLog( @"%@", nullArray[1]);
NSLog( @"%@", nullArray[2]);
//-------------类型限定词--------------//
long int a = 10;
long long int b = 100;
short int c = 1;
//只能用来存正数,如果给负数会自动变为正数 注意%u
unsigned int d = -1;
NSLog( @"%u", d);
signed char e = ‘x‘;
NSLog( @"%c", e );
//-----------id 对象 可以指向任何的对象类型---------------//(重点)
//常用于 传参 和 返回值类型
id mm = [Article new];
[mm setAuthorName: @"jabez"];
NSLog( @"%@", [mm AuthorName]);
return 0;
}
【非凡程序员】 OC第六节课 (枚举,字典,结构体,NSRange,CG类型,NSnumber,空)
标签:
原文地址:http://my.oschina.net/u/2366900/blog/416992