zoukankan      html  css  js  c++  java
  • 装箱和拆箱

    C的基本类型使用NSNumber

    装箱        NSNumber *ageNumber = [NSNumber numberWithInt:23];

                  NSNumber *ageNumber2 = @23;

          

    拆箱        int age = [ageNumber intValue];

            

    C的复合类型结构用NSValue

    创建

            CGPoint origin = CGPointMake(10, 10);

            CGSize size = CGSizeMake(20, 20);

            CGRect rect = CGRectMake(10, 10, 20, 20);

    访问具体的变量

            CGFloat x = rect.origin.x;

            CGFloat y = rect.origin.y;

            CGFloat width = rect.size.width;

            CGFloat height = rect.size.height;

    装箱

            NSValue *rectV = [NSValue valueWithRect:rect];

            NSValue *pointV = [NSValue valueWithPoint:origin];

            NSValue *sizeV = [NSValue valueWithSize:size];

    拆箱        

            CGRect rect1  = [rectV rectValue];

            NSLog(@"%@", rectV);

     

    -----------ps------------------------------------------------------------

             struct CGPoint {

                CGFloat x;

                CGFloat y;

             };

             struct CGSize {

             CGFloat width;

             CGFloat height;

             };

             struct CGRect {

             CGPoint origin;

             CGSize size;

             };

     

  • 相关阅读:
    求100内的数和
    汉诺塔(印度传说)
    ORA-06502:PL/SQL:数字或值错误:数值精度太高
    触发器的编写
    mysql改密码
    LeetCode-238 Product of Array Except Self
    LeetCode-236 Lowest Common Ancestor of a Binary Tree
    LeetCode-233 Number of Digit One
    LeetCode-230 Kth Smallest Element in a BST
    LeetCode-229 Majority Element II
  • 原文地址:https://www.cnblogs.com/huoran1120/p/5072578.html
Copyright © 2011-2022 走看看