Object-c------NSNumber 및 NSValue에 대한 간단한 설명

4686 단어
NSNumber main.m
//
// main.m
// NSNumber
//
// Created by zhaogang on 16/5/8.
// Copyright © 2016  zhaogang. All rights reserved.
//

#import <Foundation/Foundation.h>

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

    //@20  20 NSNumber 
    NSArray *array = @[

      @{@"name" : @"jack" , @"age" : @20},
      @{@"name" : @"rose" , @"age" : @21},
      @{@"name" : @"hobe" , @"age" : [NSNumber numberWithInt:19]}


      ];

    //  NSNumber 
    @10.5;

    @YES;

    @'a'; // NSNumber 

    @"a"; // NSString 

    //  age NSNumber 
    int age = 10;
    @(age);


    NSNumber *n = [NSNumber numberWithDouble:10.5];
    int d = [n doubleValue];

    int a = 20;
    NSString *str = [NSString stringWithFormat:@"%d",a];
    [str intValue];

    return 0;
}

void test()
{
    NSNumber *num = [NSNumber numberWithInteger:10];

    NSDictionary *dict =  @{
                            @"name" : @"jack",
                            @"address" : @"beijing",
                            @"age" : num
                            };

    NSNumber *num2 = dict[@"age"];

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

NSValue main.m
//
// main.m
// NSValue
//
// Created by zhaogang on 16/5/8.
// Copyright © 2016  zhaogang. All rights reserved.
//

#import <Foundation/Foundation.h>

// NSNumber , NSValue


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

    //  --->  

    CGPoint p = CGPointMake(10, 10);

    // Value 
    NSValue *value = [NSValue valueWithPoint:p];

    //  value 
    //[value pointerValue];

    NSArray *array = @[value];



    return 0;
}

좋은 웹페이지 즐겨찾기