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

iOS 7 Pushing the Limits - Good & Bad Namings in Cocoa的更多相关文章

  1. iOS 7 Pushing the Limits Notes - create a layer like notification center's or control center's background

    Problem: How to create a layer that looks like your notification center's or control center's backgr ...

  2. [iOS翻译]《iOS 7 Programming Pushing the Limits》系列:你可能不知道的Objective-C技巧

    简介: 如果你阅读这本书,你可能已经牢牢掌握iOS开发的基础,但这里有一些小特点和实践是许多开发者并不熟悉的,甚至有数年经验的开发者也是.在这一章里,你会学到一些很重要的开发技巧,但这仍远远不够,你还 ...

  3. Android Programming: Pushing the Limits -- Chapter 7:Android IPC -- ApiWrapper

    前面两片文章讲解了通过AIDL和Messenger两种方式实现Android IPC.而本文所讲的并不是第三种IPC方式,而是对前面两种方式进行封装,这样我们就不用直接把Aidl文件,java文件拷贝 ...

  4. Android Programming: Pushing the Limits -- Chapter 7:Android IPC -- Messenger

    Messenger类实际是对Aidl方式的一层封装.本文只是对如何在Service中使用Messenger类实现与客户端的通信进行讲解,对Messenger的底层不做说明.阅读Android Prog ...

  5. Android Programming: Pushing the Limits -- Chapter 7:Android IPC -- AIDL

    服务端: 最终项目结构: 这个项目中,我们将用到自定义类CustomData作为服务端与客户端传递的数据. Step 1:创建CustomData类 package com.ldb.android.e ...

  6. Android Programming: Pushing the Limits -- Chapter 6: Services and Background Tasks

    什么时候使用Service 服务类型 开启服务 后台运行 服务通信 附加资源 什么时候使用Service: @.任何与用户界面无关的操作,可移到后台线程,然后由一个Service来控制这个线程. 服务 ...

  7. Android Programming: Pushing the Limits -- Chapter 5: Android User Interface Operations

    多屏幕 自定义View 多屏幕 @.Android 4.2 开始支持多屏幕. @.举例: public class SecondDisplayDemo extends Activity { priva ...

  8. Android Programming: Pushing the Limits -- Chapter 4: Android User Experience and Interface Design

    User Stories Android UI Design 附加资源 User Stories: @.通过写故事来设计应用. @.每个故事只关注一件事. @.不同的故事可能使用相同的组件,因此尽早地 ...

  9. Android Programming: Pushing the Limits -- Chapter 3: Components, Manifests, and Resources

    Android Components Manifest文件 Resource and Assets v\:* {behavior:url(#default#VML);} o\:* {behavior: ...

随机推荐

  1. Java读写大文本文件(2GB以上)

    如下的程序,将一个行数为fileLines的文本文件平均分为splitNum个小文本文件,其中换行符'r'是linux上的,windows的java换行符是'\r\n': package kddcup ...

  2. LR录制脚本IE不能打开解决方法

    运行环境:win7 64位 解决方法:1.卸载IE11 2.计算机——属性——高级系统设置——性能里的设置——数据执行保护——选择“为除下列选定程序之外的所有程序和服务启用”——添加IE浏览器和VUG ...

  3. CMDB反思5

    ITSM工具规划设计 http://blog.vsharing.com/xqscool/A946789.html 相比PPT中被管的数个对象(像培训什么的也都在其中),我们的需求其实就要小得多,但是问 ...

  4. 中文+django1.9+python3.5一些注意点

    1.模板html文件里一定要加 <!DOCTYPE html><meta http-equiv="Content-type" content="text ...

  5. 传统IT大佬们,路在何方?

    [文/ 任英杰] 2014年第一季度季报陆续出台,互联网公司无疑仍是璀璨明星,一路凯歌,而与互联网企业的蒸蒸日上形成鲜明对照的是传统IT企业的集体黯然失色.分析一下传统IT大佬们发布的数据,用友营业收 ...

  6. DouNet学习_代码生成器

    string conn = "Data Source={0};Initial Catalog={1};User Id={2};Password={3}"; //点击链接 priva ...

  7. 邮件发送服务AWS SES,Mailgun以及SendCloud(转)

    原文:http://www.l4zy.com/posts/aws_ses-mailgun-sendcloud.html 电子邮件这一已经诞生很多年的互联网基础服务并没有随着时间的推移而慢慢消亡,实际上 ...

  8. Android SDK无法更新解决方法

    我这里主要说的是mac下如何设置Android SDK更新,windows下类似 首先说明为什么要这么麻烦,没办法身处在大天朝中,伟大的防火墙,苦逼的程序猿想要查点资料都是非常难的.不废话了,下面进入 ...

  9. <<海闻电子发票接口 ESB 封装文档>>

    <<海闻电子发票接口 ESB 封装文档>> 章节目录结构: 发票验证接口 发票开具接口 ESB请求地址: 发票验证接口: http://10.15.22.120:8866/42 ...

  10. 好用的编辑框布局控件TdxLayoutControl

    TdxLayoutControl是编辑框的容器,里面的编辑框可以自动对齐,自由拖放,异常方便.