zoukankan      html  css  js  c++  java
  • 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所在的对象(视图控制器)除了知道那个对象实现了协议方法外,不需要知道任何其他东西

  • 相关阅读:
    向日葵、阳光
    laravel还是给我太多惊喜了
    滴滴笔试题——小试牛刀
    剑指offer——二叉搜索树的后序遍历序列
    2019春招美团笔试
    首次实习生招聘会——航天一院
    有趣的数字
    剑指offer——从上往下打印二叉树
    剑指offer——栈的压入、弹出序列
    剑指offer——包含min函数的栈
  • 原文地址:https://www.cnblogs.com/guitarandcode/p/5445890.html
Copyright © 2011-2022 走看看