OC:鏁扮粍鐨勯亶鍘嗘柟寮�

objective-c 璇█ 鏁扮粍閬嶅巻鐨�4绉嶆柟寮忥細1銆佹櫘閫歠or寰幆锛�2銆佸揩閫焒or寰幆锛�3銆佺壒鎬lock鏂规硶锛�4銆佹灇涓炬柟娉�

Blog绫伙細


```

```#import "Blog.h"

android {

buildTypes {

debug {

testCoverageEnabled = true

}

}

}


@implementation Blog

+(Blog *)blog{

Blog * blog = [[Blog alloc] init];

returnblog;

}

-(Blog *)setBlogTitle:(NSString *)title andContent:(NSString *)content{

_title = title;

_content = content;

returnself;

}

-(NSString *)description{

return[NSString stringWithFormat:@"blog : title is \"%@\" , and content is \"%@\"", _title,_content ];

}

-(void)dealloc{

NSLog(@"%@琚攢姣佷簡",self.title);

}

涓诲嚱鏁�锛�

#pragma mark Array鏁扮粍鐨勫洓绉嶉亶鍘嗘柟娉�

voidtestArray(){

Blog *blog1 = [[Blog blog] setBlogTitle:@"Love"andContent:@"I love you"];

Blog *blog2 = [[Blog blog] setBlogTitle:@"Friendship"andContent:@"you are my best friend"];

NSArray *array = [NSArray arrayWithObjects:@"hello",@"world",blog1,blog2, nil];

//绗竴绉嶉亶鍘嗭細鏅�歠or寰幆

longintcount = [array count];

for(inti = 0 ; i < count; i++) {

NSLog(@"1閬嶅巻array: %zi-->%@",i,[array objectAtIndex:i]);

}

//绗簩绉嶉亶鍘嗭細蹇�焒or寰幆,闇�瑕佹湁澶栧彉閲廼

inti = 0;

for(id obj in array) {

NSLog(@"2閬嶅巻array锛�%zi-->%@",i,[array objectAtIndex:i]);

i++;

}

//绗笁绉嶉亶鍘嗭細OC鑷甫鏂规硶enumerateObjectsUsingBlock:

//榛樿涓烘搴忛亶鍘�

[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx,BOOL*stop) {

NSLog(@"3閬嶅巻array锛�%zi-->%@",idx,obj);

}];

//NSEnumerationReverse鍙傛暟涓哄�掑簭閬嶅巻

[array enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx,BOOL*stop) {

NSLog(@"4鍊掑簭閬嶅巻array锛�%zi-->%@",idx,obj);

}];

//绗洓绉嶉亶鍘嗭細鍒╃敤鏋氫妇

NSEnumerator *en = [array objectEnumerator];

id obj;

intj = 0 ;

while(obj = [en nextObject]) {

NSLog(@"5閬嶅巻array锛�%d-->%@",j,obj);

j++;

}

}

intmain(intargc,constchar* argv[])

{

@autoreleasepool {

testArray();

}

return0;

}

```


缁撴灉锛�

OC:鏁扮粍鐨勯亶鍘嗘柟寮�_第1张图片

你可能感兴趣的:(OC:鏁扮粍鐨勯亶鍘嗘柟寮�)