• Object -C NSNumber -- 笔记


    //

    //  main.m

    //  NSNumber

    //

    //  Created by facial on 24/8/15.

    //  Copyright (c) 2015 facial_huo. All rights reserved.

    //

     

    #import <Foundation/Foundation.h>

     

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

        @autoreleasepool {

            // insert code here...

            NSLog(@"Hello, World!");

            

            NSNumber *intNumber = [[NSNumber alloc] initWithInt: 1];

            NSNumber *floatNumner = [[NSNumber alloc] initWithFloat:1.0f];

            NSNumber *doubleNumber = [[NSNumber alloc] initWithDouble: 3.33];

            NSNumber *charNumber = [[NSNumber alloc] initWithChar: 'A'];

            

            //比较数字大小

            NSNumber *intNumber2 = [[NSNumber alloc] initWithInt:2];

            bool ret = [intNumber2 isEqualToNumber: intNumber];  // intNumber = 1, intNumber = 2. so ret = 0;

            NSLog(@"%d",ret);

            

            

            //比较float and int

            bool ret2 = [intNumber isEqualToNumber: floatNumner];

                // int intBumber = 1, floatNumber = 1.0f, so ret2 = 0;

            

            //比较

            

            NSNumber *num1 = [[NSNumber alloc] initWithInt: 10 ];

            NSNumber *num2 = [[NSNumber alloc] initWithInt: 10 ];

            

            

            if( [num1 compare:num2] == NSOrderedAscending  ) {

                NSLog(@" < ");

            }else if([num1 compare:num2] == NSOrderedDescending) {

                NSLog(@">");

            }else if ([num1 compare:num2] == NSOrderedSame){

                NSLog(@"==");

            }

            

            // NSNumber 类型转回去普通的类型

            NSLog(@"%d", [intNumber intValue]);

            NSLog(@"%f", [floatNumner floatValue]);

            NSLog(@"%f", [doubleNumber doubleValue]);

            NSLog(@"%c", [charNumber charValue]);

     

     

            

            

            

            

            

     

            

            

            

            

            

        }

        return 0;

    }

  • 相关阅读:
    [论文理解] MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
    [论文理解] Connectionist Text Proposal Network
    [期末复习] 数据结构期末复习
    [机器视觉] 实际场景字提取
    [论文理解]Deep Residual Learning for Image Recognition
    [学习笔记] AD笔记
    [OpenMP] 并行计算入门
    [Docker] Docker安装和简单指令
    python初级装饰器编写
    web页面简单布局的修改,测试中的应用
  • 原文地址:https://www.cnblogs.com/facial/p/4756229.html
Copyright © 2020-2023  润新知