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

  • 相关阅读:
    python之openpyxl模块(最全总结 足够初次使用)
    随笔 遇见
    浅析企业服务器安全防护的七个切入点
    jQuery.API源码深入剖析以及应用实现(1) - 核心函数篇
    常用Javascript精选(二)
    随笔 生活与生命
    jquery插件 8个很有用的jQuery插件
    jquery插件 5个小插件
    常用Javascript精选(一)
    jQuery库与其他JS库冲突的解决办法(转)
  • 原文地址:https://www.cnblogs.com/guitarandcode/p/5445890.html
Copyright © 2011-2022 走看看