本帖最后由 Abuzzworld 于 2015-10-8 16:07 编辑
- .h文件
- #import <Foundation/Foundation.h>
- typedef enum {kColorBlack,kColorWhite,kColorTHJ}COLOR;
- @interface IPhone : NSObject
- @property(nonatomic,assign)COLOR color;
- +(NSString*)hohohahei:(IPhone*)iPhone;
- @end
复制代码
- .m文件
- #import "IPhone.h"
- @implementation IPhone
- +(NSString*)hohohahei:(IPhone*)iPhone{
- NSString *color;
- switch ([iPhone color]) {
- case 0:
- color = @"黑色";
- break;
-
- case 1:
- color = @"白色";
- break;
-
- case 2:
- color = @"土豪金";
- break;
-
- default:
- break;
- }
- return color;
- }
- @end
复制代码- main入口文件
- #import <Foundation/Foundation.h>
- #import "IPhone.h"
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
-
- IPhone *shouji = [[IPhone alloc]init];
- [shouji setColor:kColorBlack];
- NSLog(@"手机颜色是:%@",[IPhone hohohahei:shouji]);
- }
- return 0;
- }
复制代码
|
|