//
// main.m
// chapter8
//
// Created by jimzhai on 13-1-28.
// Copyright (c) 2013年 jimzhai. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Car : NSObject
{
int V;
int speed;
}
+(void)brakeDown;
-(int)getV;
-(void)setV:(int)V;
-(int)getSpeed;
-(void)setSpeed:(int)speed;
@end
@implementation Car
- (id)init
{
self = [super init];
if (self) {
V=0;
speed=0;
}
return self;
}//init
+ (void)brakeDown
{
NSLog(@"car is broken!");
}//brakeDown
- (int)getV
{
return V;
}//getV
-(void)setV:(int)_V
{
V=_V;
}
-(void)setSpeed:(int)_speed
{speed=_speed;}
-(int)getSpeed
{
return speed;
}
@end
int main(int argc, const char * argv[])
{
id car = [Car new];
NSLog(@"car V: %d car speed: %d",[car getV],[car getSpeed]);
[Car brakeDown];
NSString *str1 = @"abcdefg";
NSString *str2 = @"abcdefh";
NSString *str3 = @"abcdefg";
if([str1 isEqualToString:str2])
NSLog(@"str1 is equal str2");
if([str1 isEqualToString:str3])
NSLog(@"str1 is equal str3");
NSRange rang;
rang = [str1 rangeOfString:@"cde"];
NSString *str4 = [str1 stringByReplacingOccurrencesOfString:@"cde" withString:@"iii"];
NSLog(@"%@",str4);
NSArray *str = [NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",nil ];
NSArray *array = [NSArray arrayWithArray:str];
[str objectAtIndex:5];
for(int i = 0 ; i < [array count]; i++)
NSLog(@"%@",[array objectAtIndex:i]);
return 0;
}
Object-C 练习
最新推荐文章于 2020-12-23 22:45:58 发布