61,对象作为返回值

#import


@interface Gun : NSObject


-(void)about;


@end


@implementation Gun


-(void)about{

    NSLog(@"这是一把冲锋枪");

}


@end




@interface Shop : NSObject


+(Gun *) buyGun:(int)money;


@end


@implementation Shop


+(Gun *) buyGun:(int)money{

    Gun *gun;

    if (money > 100) {

        gun = [Gun new];

    }

    return gun;

}


@end


int main(int argc,const char * argv[]) {

    @autoreleasepool {

        Gun *gun = [ShopbuyGun:101];

        [gun about];

    }

    return 0;

}

//2015-12-05 22:55:35.409 4,对象作为返回值[2193:302363]这是一把冲锋枪

//Program ended with exit code: 0



你可能感兴趣的:(OC)