從零開始自學ios ---第1天 Foundation的一些總結

#import <Foundation/Foundation.h>
int main(int argc,const char *argv[])
{
@autoreleasepool {
//insert code here
NSLOG(@"hello,World");
}
}
//結構體NSRange
typedef struct _NSRange{
unsigned int Location;
unsigned int Length;
}NSRange;
//Location 字段存放該字段的起始位置,Length:所含元素的個數
//創建新的NSRange有3種方式
NSRange range;
range.Location=17;
range.Length=4;
//2 聚合結構賦值機制
NSRange range=[17,4];
//3 Cocoa 提供的快捷函數 NSMakeRange();使用它可以在任何能夠使用函數的地方使用它
//例如在方法調用中將其作爲參數進行傳遞
[anObject flabulateWithRange:NSMakeRange(13,15)];
NSRange range=NSMakeRange(17,4);
//2集合數據類型 CG 由Core Graphics(製圖)提供
//CGPoint 笛卡爾平面中的一個座標 cocos2d也用到
struct CGPoint
{
float X;
float Y;
}
//CGSize 用來儲存長度和寬度:
struct CGSize
{
float width;
float height;
}
//矩形數據類型 CGRect
struct CGRect
{
CGPoint origin;
CGSize size;
}
//Cocoa 也爲我們提供了這些數據類型的快捷函數:CGPointMake(),CGSizeMake(),CGRectMake();
*///字符串NSString 的stringWithFormat:方法就是通過格式字符串和參數來創建的NSString
+(id)stringWithFormat:(NSString *)format,...;
//創建新字符串
NSString *height;
height=[NSString stringWithFormat:@" Your hegiht is %d feet,%d inches",5,11];
//+,就是把方法定義類方法(class method) 用於創建新的實例
NSColor * haveTheBules=[NSColor blueColor];
UIColor * blueman=[UIColor blueColor]
//NSSTring中另一個好用的方法是length,它返回的時字符串的字符個數
-(NSUInteger) Length;
//可以這樣用它
NSUInteger Length=[height Length];
if ([height Length]>35)
{
NSLOG(@"wow,you're really tall!");
}
//字符串比較isEquaLToString: 其返回BOOL值 比較字符串內容是否相同
-(BOOL)isEqualToString:(NSString *)aString;
NSString *thing1=@"hello 5";
NSString *thing2=[NSString stringWithFormat:@"hello %d",5];
if([thing1 isEqualToString:thing2])
{
NSLOG(@"They are the same")
}
//要比較兩個字符串,可以使用compare:方法
-(NSComoarionResult)compare:(NSString *)aString;
//compare:options:
-(NSComoarionResult) compare:(NSString *)aString
options:(NSStringCompareOptions)mask;
//NSCaseInsensitiveSrarch:不區分大小寫字符
//NSLiteralSearch:進行完全比較,區分大小寫字符
//NSNumericSearch:比較字符串個數,而不是字符串串值。
if([thing1 compare:thing2 options:NSCaseInsensitiveSrarch|NSNumericSearch]==NSOrderedSame)
{
NSLOG(@"They match!");
}
//檢查字符串是否以另一個字符串開頭,判斷字符串是否以另一個字符串結尾
-(BOOL)hasPrefix:(NSString *)aString;
-(BOOL)hasSuffix:(NSString *)aString;
NSString*filename=@"draft-chapter.pages";
if([filename hasPrefix:@"draft"])
{
//this is a draft
}
if([filename hasSuffix:@".MOV"])
{
//
}
-(NSRange)rangeOfString:(NSString *)aString;//返回NSRange結構體
//可變性 NSMutableString
-(void) appendString:(NSString *)aString;
-(void)appendFormat:(NSString *)format,...;//增加字符串
NSMutableString*friends=[NSMutableString stringWithCapacity:50 ];
[friends appendString:@"James BethLynn Jack Evan"];
NSRange JackRange=[friends rangeOfString:@"Jack"];
JackRange.Length++;//
[friends deleteCharactersInRange:JackRange];
NSMutableString *string=[NSMutableString stringWithFormat:@"Jo%dy",2];
//集合大家族
NSArray *array2=@[@"one",@"two",@"three"];
-(NSUInteger)count;
-(id)objectAtIndex:(NSUInteger)index;
id*myObject=array1[1];
for(NSInteger i=0;i<[array count];i++)
{
NSLOG(@"index %d has %@.",i,[array objectAtIndex:i]);
}
for(NSInteger i=0;i<[array count];i++)
{
NSLOG(@"index %d has %@.",i,array[i]);
}
//可變數組
+(id)arrayWithCapacity:(NSUInteger)numTtems;
//循環加入4個輪胎
for (NSInteger i=0;i<4;i++)
{
Tire *tire=[Tire new];
[array addObject:tire];
}
//刪除對象
-(void)removeObjectAtIndex:(NSUInteger)index;
[array removeObjectAtIndex:1];
發佈了22 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章