#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 下一個對象spa
{
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" : @"西安"
}; //第二種方法rem
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"] );字符串
//------------------結構體------------//string
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]);it
//---------------------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]);io
return 0;
}table