欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

OC变量数据类型

发布时间:2023/12/20 编程问答 48 豆豆
生活随笔 收集整理的这篇文章主要介绍了 OC变量数据类型 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

2019独角兽企业重金招聘Python工程师标准>>>

// //  main.m //  OC10变量数据类型 // //  Created by Zoujie on 15/9/4. //  Copyright (c) 2015年 Zoujie. All rights reserved. // enum flag {FIREST,SECOND,THIRD,FOURTH=5,FIFTH,}ENDOFDATA;//未命名的枚举类型 enum {up,down,left = 10,right,};enum boolean {no = 0,false = 0,yes = 1,ture = 1, };enum Month {january = 1,february,march ,april,may ,june,july,august,september,october,november,december };typedef int  Counter;//增加了变量定义的可读性typedef enum{east,west,north,south }Direction ;#import <Foundation/Foundation.h> #import "Fraction.h"typedef Fraction *  NumberObject; typedef Fraction * FractionObj;int main(int argc, const char * argv[]) {@autoreleasepool {Fraction *myFtactin = [[Fraction alloc]init];[myFtactin setTo:10 over:20];Fraction *a = [[Fraction alloc]init];Fraction *b = [[Fraction alloc]init];[a setTo:1 over:3];[b setTo:3 over:7];[a print];[b print];NSLog(@"Fractions allocated :%i",[Fraction count]);a = [[Fraction allocF] init];b = [[Fraction allocF] init];Fraction *c = [[Fraction allocF] init];NSLog(@"Fractions allocated :%i",[Fraction count]);//枚举 //        enum flag {FIREST,SECOND,THIRD};switch (ENDOFDATA) {case FIREST:NSLog(@"first==%d",FIREST);break;case SECOND:NSLog(@"second");break;case THIRD:NSLog(@"third");break;case FOURTH:NSLog(@"fourth");break;case FIFTH:NSLog(@"fifth");break;default:break;}enum flag ONE,TWO;if (ONE){NSLog(@"ONE");};if (TWO){NSLog(@"TWO");};enum Month amoth;int days;NSLog(@"Enter month number:");scanf("%i",&amoth);switch (amoth) {case january:case april:case may:case june:case july:case august:case october:case december:days = 31;break;case march:case september:case november:days = 30;break;case february:days = 28;break;default:NSLog(@"bad month number");days = 0;break;}if (days != 0)NSLog(@"Number of days is %i",days);if (amoth == february)NSLog(@"...or 29 if it's a leap year");Counter  x = 2 , y = 3;NSLog(@"%d",x);NumberObject myValue1,myValue2,myValue3;//定义的三个Fraction对象Direction stpe1,stpe2;switch (stpe1){case east:NSLog(@"%i",east);break;default:break;}FractionObj f1 = [[Fraction alloc]init];FractionObj f2 = [[Fraction alloc]init];}return 0;} // //  Fraction.h //  OC10变量数据类型 // //  Created by Zoujie on 15/9/4. //  Copyright (c) 2015年 Zoujie. All rights reserved. //#import <Foundation/Foundation.h>@interface Fraction : NSObject {} @property (nonatomic ,assign) NSInteger a; @property (nonatomic ,assign) NSInteger b;-(void)setTo:(int)a over:(int) b;-(instancetype)initWith:(int) a over:(int) b;//自定义初始化,所有的初始化方法都以init开头-(void)print;+(Fraction *)allocF; +(int)count; @end // //  Fraction.m //  OC10变量数据类型 // //  Created by Zoujie on 15/9/4. //  Copyright (c) 2015年 Zoujie. All rights reserved. //#import "Fraction.h" static int gGlobalVar = 0; //静态变量 static int gCounter; @implementation Fraction-(instancetype)init//重载init方法 {self = [super init];//首先调用父类的init方法if (self){NSLog(@"111111");}return self; }-(Fraction *)initWith:(int) a over:(int) b {self = [super init];if (self){[self setTo:a over:b];}return self; }-(void)setTo:(int)a over:(int)b {_a = a;_b = b;}-(void)print {NSLog(@"%ld/%ld",_a,_b); }+(Fraction *)allocF {extern int gCounter;++gCounter;return [Fraction alloc]; }+(int) count {extern int gCounter;return gCounter; }@end


转载于:https://my.oschina.net/u/2319073/blog/501146

总结

以上是生活随笔为你收集整理的OC变量数据类型的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。