• objective-c技巧,细节


    1.绝对值函数abs(),可用于求两个数值之间的差距

    2.如果代码如下:

     if (some condition) {

      something = YES;

      } else {

      something = NO;

      } 

    则,可用something = (some condition); 代替

     3.用Properties的好处有两个:

      (1)方便,省代码:the compiler automatically adds the setText and text methods to your object, as well as the instance variable that will hold the     value for this property. Now you can simply use dot syntax to read and write the value of text. 

       (2)符合面向对象的封装性:when you put properties in the @interface to make data available to others,you use properties these other objects never     directly access your internal instance variables, they always go through a getter or setter method first. 

     4.id类型常用的地方:

      You’ll often use id to describe an object that conforms to a specific protocol, without having to know anything about its class. That’s what you’ve been doing for your delegates all along: 

      @property (nonatomic,weak) id <ItemDetailViewControllerDelegate> delegate;

      The notation id <ItemDetailViewControllerDelegate> means: “I only care that this object implements the ItemDetailViewControllerDelegate protocol but its actual class is not important to me.” 

      该delegate指向实现了ItemDetailViewControllerDelegate协议方法的对象(视图控制器),但delegate所在的对象(视图控制器)除了知道那个对象实现了协议方法外,不需要知道任何其他东西

  • 相关阅读:
    如果你也用过struts2.简单介绍下springMVC和struts2的区别有哪些?
    人事面试
    人事面试
    人事面试
    java 数字和日期处理
    jsp文件导包
    asp.net MVC中使用Autofac小结 (遇到的最傻错误: 没有为该对象定义无参数的构造函数)
    Asp.net MVC 单元测试 简要笔记
    NewtonJson中转义的斜杠和多余的引号处理
    RecyclerView onTouch & onClick 触摸事件与点击事件
  • 原文地址:https://www.cnblogs.com/guitarandcode/p/5445890.html
Copyright © 2020-2023  润新知