zoukankan      html  css  js  c++  java
  • iOS 7 Pushing the Limits

    Cocoa is a dynamically typed language, and you can easily get confused about what type you are working with.
    Collections (arrays, dictionaries, and so on) don’t have types associated with them, so it’s very easy to code
    something accidentally like this:


    NSArray *dates = @[@”1/1/2000”];
    NSDate *firstDate = [dates firstObject];

    This code compiles without a warning, but will crash with an unknown
    selector exception.

    Let's look at following code lines:

    - (void)setURL:(NSString *)URL;              // Bad

    - (void)setURLString:(NSString *)string;  // Good
    - (void)setURL:(NSURL *)URL;                // Good

    category methods

    Because of the possibility of collisions, you should add a prefix to your category methods

    Cocoa generally doesn’t use embedded underscores

    A good use of categories is to provide utility methods to existing classes. When you do this, I recommend
    naming the header and implementation files using the name of the original class plus the name of the
    extension.

    For example, you might create a simple PTLExtensions category on NSDate:

    NSDate+PTLExtensions.h

    @interface NSDate (PTLExtensions)
    - (NSTimeInterval)ptl_timeIntervalUntilNow;
    @end

    NSDate+PTLExtensions.m

    @implementation NSDate (PTLExtensions)
    - (NSTimeInterval)ptl_timeIntervalUntilNow {
      return -[self timeIntervalSinceNow];
    }
    @end
  • 相关阅读:
    前端大文件上传方法(深度好文)
    windows版idea 2018.3.5版 永久激活教程
    性能优化随笔
    使用java画一张海报
    Gson杂记录
    Gson转Map时,Int会变成double解决方法
    浅析VO、DTO、DO、PO的概念、区别和用处
    SpringCloud框架搭建+实际例子+讲解+系列五
    raid总结
    MD5与SHA1
  • 原文地址:https://www.cnblogs.com/davidgu/p/3912842.html
Copyright © 2011-2022 走看看