当前位置: 首页 > news >正文

OC变量数据类型

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

//
//  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

相关文章:

  • win7 蛋疼的时间格式转化
  • MacBook: 安装Mac OS X与多分区Windows双系统完美教程
  • ecshop如何判断缓存文件是否能更新
  • 登录信息提示
  • 某银行网银代发工资无法操作问题解决
  • SpringMVC文件上传
  • Magento 1.x 中文订单打印乱码
  • ios 控件代码transform学习笔记
  • DataTable和Xml互相转化
  • 机器学习温和指南
  • 打印xls注意事项
  • JSPpage与pageContext什么关系
  • django 1.8 官方文档翻译:13-3 日志
  • FTP使用
  • Linq左关联 右关联 内关联
  • [数据结构]链表的实现在PHP中
  • ➹使用webpack配置多页面应用(MPA)
  • Akka系列(七):Actor持久化之Akka persistence
  • android高仿小视频、应用锁、3种存储库、QQ小红点动画、仿支付宝图表等源码...
  • Angular 4.x 动态创建组件
  • Angular2开发踩坑系列-生产环境编译
  • bootstrap创建登录注册页面
  • CentOS学习笔记 - 12. Nginx搭建Centos7.5远程repo
  • java2019面试题北京
  • Java新版本的开发已正式进入轨道,版本号18.3
  • Selenium实战教程系列(二)---元素定位
  • SpringBoot几种定时任务的实现方式
  • 二维平面内的碰撞检测【一】
  • 分享一份非常强势的Android面试题
  • 开发基于以太坊智能合约的DApp
  • 买一台 iPhone X,还是创建一家未来的独角兽?
  • 爬虫模拟登陆 SegmentFault
  • 三栏布局总结
  • 实战|智能家居行业移动应用性能分析
  • 小程序、APP Store 需要的 SSL 证书是个什么东西?
  •  一套莫尔斯电报听写、翻译系统
  • 移动端唤起键盘时取消position:fixed定位
  • 用 vue 组件自定义 v-model, 实现一个 Tab 组件。
  • 用简单代码看卷积组块发展
  • 正则表达式-基础知识Review
  • $L^p$ 调和函数恒为零
  • (Git) gitignore基础使用
  • (附源码)流浪动物保护平台的设计与实现 毕业设计 161154
  • (四) 虚拟摄像头vivi体验
  • (转)Sublime Text3配置Lua运行环境
  • ***详解账号泄露:全球约1亿用户已泄露
  • .[hudsonL@cock.li].mkp勒索病毒数据怎么处理|数据解密恢复
  • .bat文件调用java类的main方法
  • .cfg\.dat\.mak(持续补充)
  • .equals()到底是什么意思?
  • .net core 6 集成和使用 mongodb
  • .NET DataGridView数据绑定说明
  • .NET Micro Framework初体验(二)
  • .net mvc部分视图
  • .NET 使用 ILRepack 合并多个程序集(替代 ILMerge),避免引入额外的依赖