foundation框架的学习介绍


Foundation框架 本章授课内容 ™Foundation框架简介 ™自动™自动回收池 ™NSNumber类 ™NSString类 ™数组对象™数组对象 Foundation简介 ™Foundation框架 框架是由许多类 方法 函数 文档按照 定的逻辑ƒ 框架是由许多类、方法、函数、文档按照一定的逻辑 组织起来的集合,以便使研发变得更容易。 ƒ 为所有程序开发奠定基础的框架是Foundation框架包ƒ 为所有程序开发奠定基础的框架是Foundation框架包 含对象集合,如数组、字典、集合。其他功能包括内 存管理、处理基础文件系统、存储对象等存管理、处理基础文件系统、存储对象等 ƒ Cocoa总的来说指的是Foundation和Application kit ƒ Cocoa Touch是Foundation和UIKitCocoa Touch是Foundation和UIKit 本章授课内容 ™Foundation框架简介 ™自动™自动回收池 ™NSNumber类 ™NSString类 ™NSArray类™NSArray类 自动回收池 ™自动回收池 自动 收池可以管理添加到该池中的对象所使用的内ƒ 自动回收池可以管理添加到该池中的对象所使用的内 存。 ƒ 向对象发送 条autorelease消息 该对象就被放到自ƒ 向对象发送一条autorelease消息,该对象就被放到自 动回收池中。 ƒ 释放回收池时 自动回收池向添加到自动回收池的所ƒ 释放回收池时,自动回收池向添加到自动回收池的所 有对象发送一条release消息。 自动回收池 ƒ 代码示例: #import @interface Complex : NSObject {{ double real; double imaginary; }} @property double real, imaginary; +(id) valueWithReal:(double)aReal andImag:(double)aImag; -(id) initWithReal:(double)aReal andImag:(double)aImag;-(id) initWithReal:(double)aReal andImag:(double)aImag; @end 自动回收池 #include "complex.h" @i l t ti l@implementation complex + (id)valueWithReal:(double)aReal andImag:(double)aImag { Complex* obj [[Complex alloc]initWithReal:aRealComplex* obj = [[Complex alloc]initWithReal:aReal andImag:aImag]; [obj autorelease]; return obj;return obj; } - (id)initWithReal:(double)aReal andImag:(double)aImag {{ if(self = [super init]) { real = aReal;ea aea; imaginary = aImag; } return self; } 自动回收池 int main() { NSAtRl P l*lNSAutoReleasePool* pool = [[NSAutoReleasePool alloc] init]; Complex *a = [[Complex alloc]initWithReal:100 andImag:100];andImag:100]; [a release]; Complex *b = [[Complex alloc]initWithReal:100Complex *b = [[Complex alloc]initWithReal:100 andImage:100]; [b autorelease]; Complex *c = [Complex valueWithReal:100 andImag:100]; [pool drain]; } 自动回收池 ƒ 每一个Cocoa线程都拥有一个autoreleasepool的栈,当 线程终止的时候 会自动释放和当前线程关联的所有线程终止的时候,会自动释放和当前线程关联的所有 autoreleasepool对象。 stack id id obj objstackThread stack AutoreleasePool AutoreleasePool id id ... obj obj ... ... id obj stack id id ... obj obj ... NSNumber类 ™NSNumber类 用于将内置类型的数据转换为NSN b 对象ƒ 用于将内置类型的数据转换为NSNumber对象 ƒ 头文件: NSNumber类 NSNumber类 ƒ 代码示例: #import #import #import #import #import #import int main (int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; [[ ]] NSNumber*myNumber, *floatNumber, *intNumber; NSInteger myInt; // integer value intNumber = [NSNumber numberWithInteger: 100]; myInt = [intNumber integerValue]; NSLog (@"%li", (long) myInt); //100 // long value myNumber = [NSNumber numberWithLong: 0xabcdef]; NSLog (@"%lx", [myNumber longValue]); //abcdef // h l// char value myNumber = [NSNumber numberWithChar: 'X']; NSLog (@"%c", [myNumber charValue]); //X NSNumber类 // float value floatNumber = [NSNumber numberWithFloat: 100.00]; NSLog (@"%g" [floatNumber floatValue]); //100NSLog (@ %g , [floatNumber floatValue]); //100 // double myNumber = [NSNumber numberWithDouble: 12345e+15]; NSLog (@"%lg", [myNumber doubleValue]); //1 2345e+19NSLog (@ %lg , [myNumber doubleValue]); //1.2345e+19 // Wrong access here NSLog (@"%i", [myNumber integerValue]); //0 // Test two Numbers for equality// q y if ([intNumber isEqualToNumber: floatNumber] == YES) NSLog (@"Numbers are equal"); //yes else NSLog(@"Numbers are not equal"); // Test if one Number is <, ==, or > second Number if ([intNumber compare: myNumber] == NSOrderedAscending) NSLog (@"First number is less than second"); //yes [pool drain]; return 0; } NSNumber类 ™注意事项: 以 ll 创建的对象不会添加到自动 收ƒ 以new、alloc、copy创建的对象不会添加到自动回收 池,其他方法创建的对象都会放入自动回收池 ƒ NSInterger不是 个对象而是基本数据类型的ƒ NSInterger不是一个对象,而是基本数据类型的 typedef。它代表64位或者32位的int,用于处理程序中 没有初值的整数没有初值的整数 NSNumber类 ƒ integerValue:等检索实例方法不会检查所提取的数据 类型是否符合方法要求类型是否符合方法要求 ƒ compare:比较两个NSNumber对象 NSOrderedAscending;NSOrderedDescending;NSOrNSOrderedAscending;NSOrderedDescending;NSOr derSame; t pedef en m NSComparisonRes lt{typedef enum _NSComparisonResult{ NSOrderedAscending = -1, NSOrderedSame, NSOrderedDescendingNSOrderedDescending } NSComparisonResult; NSNumber类 ƒ 初始化方法: int main (int argc, char *argv[]) { NSAutoReleasePool* pool = [[NSAutoReleasePool alloc] init]; NSNumber *myNumber = [NSNumber numberWithInt:100]; myNumber = [[NSNumber alloc]initWithInt:100]; [myNumber release]; [pool drain]; } 本章授课内容 ™Foundation框架简介 ™自动™自动回收池 ™NSNumber类 ™NSString类 ™数组对象™数组对象 NSString类 ™NSString类 用于创建和处理字符串对象的类ƒ 用于创建和处理字符串对象的类 ƒ 由Unichar组成,可以处理包含百万字符的字符集,使 其能够在全世界不同语言环境下使用其能够在全世界不同语言环境下使用 C Objective-C char Unichar NSString类 ƒ 如果在程序中使用NSString对象,需要在头文件中包 含NSString所在类的头文件:含NSString所在类的头文件: #import ƒ NSString用于创建不可变字符串对象,其子类 NSMutableString创建可变字符串NSMutableString创建可变字符串 NSString类 ™NSLog函数 NSL 可以用来打印内置类型 NSSt i 类型对象ƒ NSLog可以用来打印内置类型,NSString类型对象, 同样也可以用来打印自定义类对象。 int main (int argc, char *argv[]) { NSAutoReleasePool* pool = [[ llll ]ii][[NSAutoReleasePool alloc] init]; NSString *str = @"Programming is fun"; NSLog(@"%@",str); [pool drain]; return 0; }} NSString类 ƒ 打印NSNumber对象 int main (int argc, char *argv[]) { NSAutoReleasePool* pool = [[NSA t R l P l ll ] i it][[NSAutoReleasePool alloc] init]; NSNumber *intNumber = [NSNumber numberWithInteger:100]; NSLog(@"%@", intNumber); [pool drain];[pool drain]; return 0; } NSString类 ƒ 格式字符%@可以能够显示数组,字典和集合的全部内 容容。 ƒ 如果通过%@格式字符来打印对象信息,程序会调用 description方法返回描述对象信息的字符串。description方法返回描述对象信息的字符串。 NSObject - (id)retain - (id)release -(NSString*)description NSNumber -(NSString*)description NSString -(NSString*)description NSString类 ™NSString处理不可变字符串 代码示例ƒ 代码示例: #import #import #import int main (int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *str1 = @"This is string A"; 2@NSString *str2 = @"This is string B"; NSString *res; NSComparisonResult compareResult; // C t th b f h t// Count the number of characters NSLog (@"Length of str1: %lu", [str1 length]); //16 // Copy one string to another res = [NSString stringWithString: str1];res = [NSString stringWithString: str1]; NSLog (@"copy: %@", res); //Copy :This is string A str2 = [str1 stringByAppendingString: str2]; NSLog (@"Concatentation: %@", str2); //if ([str1 isEqualToString: res] == YES) //YES NSLog (@"str1 == res"); else NSL (@" t 1 ! ")NSLog (@"str1 != res"); compareResult = [str1 compare: str2]; if (compareResult == NSOrderedAscending) NSLog (@"str1 < str2"); //YESNSLog (@"str1 < str2"); //YES else if (compareResult == NSOrderedSame) NSLog (@"str1 == str2"); else // NSOrderedDescendingelse // NSOrderedDescending NSLog (@"str1 > str2"); // Convert a string to uppercase res = [str1 uppercaseString];res [str1 uppercaseString]; NSLog (@"Uppercase conversion: %s", [res UTF8String]); // Convert a string to lowercase res = [str1 lowercaseString];[ g]; NSLog (@"Lowercase conversion: %@", res); NSLog (@"Original string: %@", str1); [pool drain]; return 0; } NSString类 ƒ NSRange typedef struct_NSRange { NSUInteger location;SU tege ocat o ; NSUInteger length; } NSRange; NSString类 #import #import #import #import int main (int argc, char *argv[]) {{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *str1 = @"This is string A";g g NSString *str2 = @"This is string B"; NSString *res; NSRange subRange; //用于指定范围,定义在 //(中已 经包含这个头 文 件), //实际上它是结构体的typedef,包含两个分量location和length // Extract first 4 chars from string res = [str1 substringToIndex: 3]; //Thi NSLog (@"First 3 chars of str1: %@", res); // Extract chars to end of string starting at index 6 res = [str1 substringFromIndex: 5]; //is string A NSLog (@"Chars from index 5 of str1: %@", res); // Extract chars from index 8 through 13 (6 chars) res = [[str1 substringFromIndex: 8] substringToIndex: 6]; //string NSLog (@"Chars from index 8 through 13: %@", res); // An easier way to do the same thing res = [str1 substringWithRange: NSMakeRange (8, 6)]; //string NSLog (@"Chars from index 8 through 13: %@", res); // Locate one string inside another subRange = [str1 rangeOfString: @"string A"]; NSL (@"St i i t i d %l lthi%l "NSLog (@"String is at index %lu, length is %lu", subRange.location, subRange.length); //8 8 subRange = [str1 rangeOfString: @"string B"];subRange = [str1 rangeOfString: @"string B"]; if (subRange.location == NSNotFound) NSLog (@"String not found"); //YES elseelse NSLog (@"String is at index %lu, length is %lu", subRange.location, subRange.length);subRange.location, subRange.length); [pool drain]; return 0; } NSString类 ƒ NSMutableString类用于创建可以更改字符的字符串 对象对象。 ƒ NSMutableString是NSString的子类,可以使用 NSSting中定义的所有方法。NSSting中定义的所有方法。 ƒ 任何可变或不可变字符串对象在程序执行期间,总是 可以被设为完全不同的字符串对象字串象 str1 = @"This is a string" ...... t2 [t1 bti F Id 5]str2 = [str1 substringFromIndex: 5]; NSString类 #import #import #import #import int main (int argc, char *argv[])t a(t agc,ca ag[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];[[ ]] NSString *str1 = @"This is string A"; NSString *search, *replace; NSMutableString *mstr; NSRange substr; // Create immutable string from nonmutable mstr = [NSMutableString stringWithString: str1]; NSLog (@"%@", mstr); // This is string A NSLog (@”%S”, [mstr description]); NSString类 // Insert characters [mstr insertString: @" mutable" atIndex: 7]; NSLog (@"%@" mstr); //This is mutable string ANSLog (@ %@ , mstr); //This is mutable string A // Effective concatentation if insert at end [mstr insertString: @" and string B" atIndex: [mstr length]];length]]; NSLog (@"%@", mstr); // Or can use appendString directly [mstr appendString: @" and string C"];[ pp g @g]; NSLog (@"%@", mstr); // Delete substring based on range [mstr deleteCharactersInRange: NSMakeRange (16, 13)];g g NSLog (@"%@", mstr); //This is mutable String B and StringC // Find range first and then use it for deletion substr = [mstr rangeOfString: @"string B and"]; NSString类SSt g类 if (substr.location != NSNotFound) { [mstr deleteCharactersInRange: substr]; NSLog (@"%@", mstr); //This is mutable string C } [mstr setString: @"This is string A"]; NSLog (@"%@", mstr); //This is string A [mstr replaceCharactersInRange: NSMakeRange(8, 8) withString: @" a mutable string "]; S (@ %@ ) // hi i bl iNSLog (@"%@", mstr); //This is a mutable string search = @"This is"; replace = @"An example of"; bt [mt gOfStig h]substr = [mstr rangeOfString: search]; if (substr.location != NSNotFound) { [mstr replaceCharactersInRange: substr[mstr replaceCharactersInRange: substr withString: replace]; NSLog (@"%@", mstr); // An example of a mutable string }} NSString类 // Search and replace all occurrences h@""search = @"a"; replace = @"X"; substr = [mstr rangeOfString: search]; while (substr location != NSNotFound)while (substr.location != NSNotFound) { //用X替换a [mstr replaceCharactersInRange: substr withString: replace];withString: replace]; substr = [mstr rangeOfString: search]; } NSLog (@"%@", mstr);NSLog (@ %@ , mstr); [pool drain]; return 0; }} NSString类 ƒ 所有的对象到哪里去了? 均被自动添加到了自动释放池均被自动添加到了自动释放池 NSString类 NSString类 NSString类 本章授课内容 ™Foundation框架简介 ™自动™自动回收池 ™NSNumber类 ™NSString类 ™数组对象™数组对象 数组对象 ™Foundation数组是有序的对象集合。 数组的元素类型通常是 致的但不是必须ƒ 数组的元素类型通常是一致的,但不是必须 ƒ Foudation数组元素的实际类型为id型 分为 变数组 变数组后者 前者的 类ƒ 分为可变数组和不可变数组,后者是前者的子类 ƒ 头文件: 数组对象 ObjObj Array id id Obj id id Obj Obj 数组对象 //DEMO 8_5 about NSArray int main (int argc, char *argv[]){ int i;int i; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // Create an array to contain the month names// Create an array to contain the month names NSArray *monthNames = [NSArray arrayWithObjects: @"January", @"February", @"March", @"April", @"May", @"June", @"July", @"August", @"September",@ y ,@ ,@ y ,@ g ,@ p , @"October", @"November", @"December", nil ]; //必须以nil结束 NSLog (@"Month Name");g NSLog (@"===== ===="); for (i = 0; i < 12; ++i) NSLog (@" %2i %@", i + 1, [monthNames objectAtIndex: i]); [pool drain]; return 0; } 数组对象 #define MAXPRIME 50 int main (int argc, char *argv[]) { int i, p, prevPrime; BOOL iPiBOOL isPrime; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // Create an array to store the prime numbers// Create an array to store the prime numbers NSMutableArray *primes = [NSMutableArray arrayWithCapacity: 20]; // Store the first two primes (2 and 3) into the array// Store the first two primes (2 and 3) into the array [primes addObject: [NSNumber numberWithInteger: 2]]; [primes addObject: [NSNumber numberWithInteger: 3]]; 数组对象 for (p = 5; p <= MAXPRIME; p += 2) { isPrime = YES; i =1; 如果一个数不是素 数,则它一定能够 被小于或等于其平 方根的素数整除i = 1; do { prevPrime = [[primes objectAtIndex: i] integerValue]; 方根的素数整除 [[p es object t de : ] tege a ue]; if (p % prevPrime == 0) isPrime = NO; ++i; } while ( isPrime == YES && p / prevPrime >= prevPrime); // 25/3 if ( isPrime ) [primes addObject: [NSNumber numberWithInteger: p]]; } // Display the results for (i = 0; i < [primes count]; ++i) NSLog (@"%li", (long) [[primes objectAtIndex: i] integerValue]); [ldi][pool drain]; return 0; } 数组对象 ™枚举器:NSEnumerator 传统方式ƒ 传统方式: NSMutableArray *numArray = [NSMutableArray arrayWithCapacity: 2];[NSMutableArray arrayWithCapacity: 2]; [primes addObject: [NSNumber numberWithInteger: 2]]; [primes addObject: [p j [NSNumber numberWithInteger: 3]]; for( int i = 0; i<[numArray Count]; i++) { NSLog(@"%@", [numArray objectAtIndex:i]); } 数组对象 ƒ 快速枚举: NSM tableArra *n mArraNSMutableArray *numArray = [NSMutableArray arrayWithCapacity: 2]; [primes addObject: [NSNumber numberWithInteger: 2]];[NSNumber numberWithInteger: 2]]; [primes addObject: [NSNumber numberWithInteger: 3]]; for( id num in numArray )for( id num in numArray ) { NSLog(@"%@", num); }} 数组对象 ƒ 枚举器: NSM t bl A * ANSMutableArray *numArray = [NSMutableArray arrayWithCapacity: 2]; [primes addObject: [NSNumber numberWithInteger: 2]];[NSNumber numberWithInteger: 2]]; [primes addObject: [NSNumber numberWithInteger: 3]]; NSEnumerator* enumerator =[numArray objectEnumerator];NSEnumerator* enumerator = [numArray objectEnumerator]; id num; while(num = [enumerator nextObject]) {{ NSLog(@"%@", num ); } 数组对象:AddressCard实例 #import #import #import @interface AddressCard: NSObject { NSString *name;NSString *name; NSString *email; } -(id)initWithName:(NSString *) theName(id)initWithName: (NSString ) theName andEmail: (NSString *) theEmail; -(void) dealloc; -(void) setName: (NSString *) theName(od)set a e:(SSt g ) teae andEmail: (NSString *) theEmail; -(void) setName: (NSString *) theName; -(void) setEmail: (NSString *) theEmail;() ( g ) -(NSString *) name; -(NSString *) email; -(void) print; -(BOOL) isEqual: (AddressCard *) theCard; @end 数组对象:AddressCard(cont)数组对象:AddressCard(cont) #import "AddressCard.h" @implementation AddressCard@implementation AddressCard -(id)initWithName: (NSString *) theName andEmail: (NSString *) theEmail {{ if( self = [super init] ) { name = [[NSString alloc] initWithString: theName]; email = [[NSString alloc] initWithString: theEmail]; } return self; } ( id) dll-(void) dealloc { [name release]; [ill ][email release]; [super dealloc]; } 数组对象:AddressCard(cont)数组对象:AddressCard(cont) -(void) setName: (NSString *) theNameg andEmail: (NSString *) theEmail; { [name release]; name = [[NSString alloc] initWithString: theName]; [email release]; email = [[NSString alloc] initWithString: theEmail]; } -(void) setName: (NSString *) theName { [l][name release]; name = [[NSString alloc] initWithString: theName]; } (void) setEmail:(NSString *) theEmail-(void) setEmail: (NSString *) theEmail { [email release]; email = [[NSString alloc] initWithString: theEmail];email = [[NSString alloc] initWithString: theEmail]; } 数组对象:AddressCard(cont)数组对象:AddressCard(cont) -(NSString *) name{ return name;return name; } -(NSString *) email{ return email;return email; } -(BOOL) CompareName( AddressCard *add) {{ return [name Compare : [add name]]; } -(void) print{()p{ NSLog (@"===================================="); NSLog (@"| |"); NSLog (@"| %-31s |", [name UTF8String]);g g NSLog (@"| %-31s |", [email UTF8String]); NSLog (@"| |"); NSLog (@"| |"); NSLog (@"| |"); NSLog (@"| O O |"); NSLog (@"===================================="); 数组对象:AddressCard(cont)数组对象:AddressCard(cont) -(BOOL) isEqual: (AddressCard *) theCard { if ([name isEqualToString: theCard.name] == YES && [email isEqualToString: theCard.email] == YES) return YES; else return NO; } @end 数组对象:AddressCard(cont)数组对象:AddressCard(cont) #i t "Add C d h"#import "AddressCard.h" #import int main (int argc, char *argv[ ]){ NSAutoreleasePool * poolNSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSString *aName = @"Julia Kochan"; NSString *aEmail =@"jewls337@axlc com";NSString *aEmail = @ jewls337@axlc.com ; AddressCard *card1 = [[AddressCard alloc] init]; [card1 setName: aName]; [card1 setEmail: aEmail];[card1 setEmail: aEmail]; [card1 print]; [card1 release]; [pool drain];[p ]; return 0; } AddressBook //DEMO 8_9 #import #import "AddressCard.h"#import AddressCard.h @interface AddressBook: NSObject { NSString *bookName;g ; NSMutableArray *book; } @property (nonatomic, copy) NSString *bookName; @property (nonatomic, copy) NSMutableArray *book; -(id) initWithName: (NSString *) name; -(void) sort; -(void) addCard: (AddressCard *) theCard; -(void) removeCard: (AddressCard *) theCard; -(int) entries; -(void) list; -(AddressCard *) lookup: (NSString *) theName; -(void) dealloc; @d@end AddressBook(cont.) #import "AddressBook.h" @implementation AddressBook @synthesize book, bookName; // set up the AddressBook’s name and an empty book -(id) initWithName: (NSString *) name{ self = [super init]; if (self) {if (self) { bookName = [[NSString alloc] initWithString: name]; book = [[NSMutableArray alloc] init]; } return self; } -(void) sort {{ [book sortUsingSelector: @selector(compareNames:)]; } AddressBook(cont.) -(void) addCard: (AddressCard *) theCard { [book addObject: theCard]; } -(void) removeCard: (AddressCard *) theCard { [book removeObjectIdenticalTo: theCard];[book removeObjectIdenticalTo: theCard]; } -(int) entries { return [book count]; }} AddressBook(cont.) -(void) list{ NSLog (@"======== Contents of: %@ ========="NSLog (@"======== Contents of: %@ =========", bookName); for ( AddressCard *theCard in book ) //快速枚举 NSLog (@"%-20s %-32s", [theCard.name UTF8String], [theCard.email UTF8String]); NSLog (@"=================================================="); }} -(AddressCard *) lookup: (NSString *) theName{ for ( AddressCard *nextCard in book ) //快速枚举 if ( [[ tC d m] I iti C m thNm]if ( [[nextCard name] caseInsensitiveCompare: theName] == NSOrderedSame ) return nextCard; return nil; } AddressBook(cont.) -(void) dealloc { [bookName release]; [book release]; [super dealloc]; } @end //AddressBook.m AddressBook(cont.) #import "AddressBook.h" #import it i(it h* []){int main (int argc, char *argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSString *aName = @"Julia Kochan"; NSString *aEmail = @"jewls337@axlc.com"; NSString *bName = @"Tony Iannino";SSt g bae @oyao; NSString *bEmail = @"tony.iannino@techfitness.com"; NSString *cName = @"Stephen Kochan"; NSSt i * Eil @" t @k h d"NSString *cEmail = @"steve@kochan-wood.com"; NSString *dName = @"Jamie Baker"; NSString *dEmail = @"jbaker@kochan-wood.com"; AddressCard *card1 = [[AddressCard alloc] init]; AddressCard *card2 = [[AddressCard alloc] init]; AddressCard *card3 = [[AddressCard alloc] init];AddressCard *card3 = [[AddressCard alloc] init]; AddressCard *card4 = [[AddressCard alloc] init]; AddressBook *myBook = [AddressBook alloc]; AddressBook(cont.) // First set up four address cards [card1 setName: aName andEmail: aEmail]; [card2 setName: bName andEmail: bEmail]; [card3 setName: cName andEmail: cEmail]; [card4 setName: dName andEmail: dEmail]; myBook = [myBook initWithName: @"Linda’s Address Book"];[myBook initWithName: @"Linda’s Address Book"]; // Add some cards to the address book [myBook addCard: card1]; [myBook addCard: card2]; [myBook addCard: card3]; [myBook addCard: card4];[myBook addCard: card4]; // List the unsorted book [myBook list]; AddressBook(cont.) // Sort it and list it again Output: ======== Contents of: Linda’s Address[myBook sort]; [myBook list]; [card1 release]; ======== Contents of: Linda’s Address Book ========= Julia Kochan jewls337@axlc.com Tony Iannino [card2 release]; [card3 release]; [card4 release]; Tony Iannino tony.iannino@techfitness.com Stephen Kochan steve@kochan-wood.com Jamie Baker jbaker@kochan-wood com[card4 release]; [myBook release]; [pool drain]; Jamie Baker jbaker@kochan wood.com ================================ =================== ======== Contents of: Linda’s Address return 0; } Contents of: Linda s Address Book ========= Jamie Baker jbaker@kochan-wood.com Julia Kochan jewls337@axlc.comj@ Stephen Kochan steve@kochan-wood.com Tony Iannino tony.iannino@techfitness.com ================================ ================== AddressBook(cont.) AddressBook(cont.) 本章授课内容 ™Foundation框架简介 ™自动™自动回收池 ™NSNumber类 ™NSString类 ™数组对象™数组对象 void bubble_sort(MutableArray *array,int n) {{ int i,j,flag,temp; for(i = 0; i < n-1; i++) { { flag = 1; for(j = 0; j < n-i-1; j++) { { if([array[j] CompareName: array[j+1]]) { temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; flag = 0; }} } if(1 == flag) bkbreak; printf("%d ",i); } return;return; }
还剩63页未读

继续阅读

下载pdf到电脑,查找使用更方便

pdf的实际排版效果,会与网站的显示效果略有不同!!

需要 10 金币 [ 分享pdf获得金币 ] 0 人已下载

下载pdf

pdf贡献者

yi_mi_

贡献于2016-05-10

下载需要 10 金币 [金币充值 ]
亲,您也可以通过 分享原创pdf 来获得金币奖励!
下载pdf