zoukankan      html  css  js  c++  java
  • 2015.12.24 OC中的装箱

    1.C语言的基本类型使用NSNumber(bool char int long float double)

      NSNumber *ageNumber = [NSNumber nuberWithInt:23];

      NSNumber *ageNumber = @23;

      拆箱:int age = [ageNumber intValue];

    2.C语言的符合类型使用NSValue

      1.创建一个CGPoint

        表示一个点(x, y

          struct CGPoint {

            CGFloat x;

            CGFloat y;

          };

        CGPoint orgin = CGPointMake(10, 10);

      2.创建一个CGSize

        宽度和高度(width, height

                 struct CGSize {

                   CGFloat width;

                   CGFloat height;

                 };

        CGSize size = CGSizeMake(200, 300);

      3.创建一个CGRect

          一个视图在界面上的尺寸(矩形区域)

                 struct CGRect {

                   CGPoint origin;

                   CGSize size;

                 };

        CGRect rect = CGRectMake(10, 10, 200, 300);

        CGFloat x = rect.origin.x;

        CGFloat height = rect.size.height;

    对结构体进行封装:NSValue *rectV = [NSValue valueWithRect:rect];

    拆箱:      CGRect rect = [rectV rectValue];

    对自定义的结构体进行封装:

      typedef struct{

        int age;

        char *name;

      }test;

      NSValue *temp = [NSValue valueWithBytes:&temp objCType:@encode(test)];

  • 相关阅读:
    xshell 缺少mfc110u.dll
    notepad++ 常用插件
    java 发送 http post 和 get 请求(利用unirest)
    my.conf配置大全
    md5算法
    sprinboot+redis
    jq下拉插件,chosen
    springboot+idea 热部署
    Jquery 监听浏览器前进后退
    手机自带的表情入库
  • 原文地址:https://www.cnblogs.com/immustard/p/5073583.html
Copyright © 2011-2022 走看看