iOS 7 Pushing the Limits - Good & Bad Namings in Cocoa
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的更多相关文章
- 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 ...
- [iOS翻译]《iOS 7 Programming Pushing the Limits》系列:你可能不知道的Objective-C技巧
简介: 如果你阅读这本书,你可能已经牢牢掌握iOS开发的基础,但这里有一些小特点和实践是许多开发者并不熟悉的,甚至有数年经验的开发者也是.在这一章里,你会学到一些很重要的开发技巧,但这仍远远不够,你还 ...
- Android Programming: Pushing the Limits -- Chapter 7:Android IPC -- ApiWrapper
前面两片文章讲解了通过AIDL和Messenger两种方式实现Android IPC.而本文所讲的并不是第三种IPC方式,而是对前面两种方式进行封装,这样我们就不用直接把Aidl文件,java文件拷贝 ...
- Android Programming: Pushing the Limits -- Chapter 7:Android IPC -- Messenger
Messenger类实际是对Aidl方式的一层封装.本文只是对如何在Service中使用Messenger类实现与客户端的通信进行讲解,对Messenger的底层不做说明.阅读Android Prog ...
- Android Programming: Pushing the Limits -- Chapter 7:Android IPC -- AIDL
服务端: 最终项目结构: 这个项目中,我们将用到自定义类CustomData作为服务端与客户端传递的数据. Step 1:创建CustomData类 package com.ldb.android.e ...
- Android Programming: Pushing the Limits -- Chapter 6: Services and Background Tasks
什么时候使用Service 服务类型 开启服务 后台运行 服务通信 附加资源 什么时候使用Service: @.任何与用户界面无关的操作,可移到后台线程,然后由一个Service来控制这个线程. 服务 ...
- Android Programming: Pushing the Limits -- Chapter 5: Android User Interface Operations
多屏幕 自定义View 多屏幕 @.Android 4.2 开始支持多屏幕. @.举例: public class SecondDisplayDemo extends Activity { priva ...
- Android Programming: Pushing the Limits -- Chapter 4: Android User Experience and Interface Design
User Stories Android UI Design 附加资源 User Stories: @.通过写故事来设计应用. @.每个故事只关注一件事. @.不同的故事可能使用相同的组件,因此尽早地 ...
- Android Programming: Pushing the Limits -- Chapter 3: Components, Manifests, and Resources
Android Components Manifest文件 Resource and Assets v\:* {behavior:url(#default#VML);} o\:* {behavior: ...
随机推荐
- 搭建Eclipse、Resin Web开发环境
搭建Eclipse.Resin Web开发环境 一.当然是安装java开发环境 参看: Java环境的搭建 http://www.cnblogs.com/ghj1976/archive/2010/04 ...
- AFNetWorking 使用记录
1.从一个URL GET数据 方法1: NSURL * url = [NSURL URLWithString:@"http://www.weather.com.cn/data/sk/101 ...
- 发现第三方资源,chrome控制台
for(var i=0,tags=document.querySelectorAll('iframe[src],frame[src],script[src],link[rel=stylesheet], ...
- web开发中禁止因为网速慢导致重复提交数据
var checkSubmitFlg = false; function check() { if (!checkSubmitFlg) { ...
- centos配置中文显示和中文输入
我现在使用虚拟机运行centos,但是安装完成后系统显示英文,而且无法进行中文输入,这使我感到很烦躁,虽然我对自己说,这样可以逼迫自己适应全英文的环境,但作为一个中国人还是难以忍受,所以记录一下解决办 ...
- ISO-8859-1
ISO-8859-1编码是单字节编码,向下兼容ASCII,其编码范围是0x00-0xFF,0x00-0x7F之间完全和ASCII一致,0x80-0x9F之间是控制字符,0xA0-0xFF之间是文字符号 ...
- 2015-10-27 js
1.声明变量: 2.prompt属性的使用: prompt("提示框的标题","提示框的输入提示内容"); prompt的调用结果就是他输入框内的内容!!! 3 ...
- 耳机jack构造及在应用时可能出现的问题
目前市场上耳机分为4环耳机(图1所示,iphone型)和3环耳机(图2所示).4环耳机称为headset,3环耳机称为headphone,两者之间的区别就是4环耳机比3环耳机多个micphone.而J ...
- 【原创】开发Kafka通用数据平台中间件
开发Kafka通用数据平台中间件 (含本次项目全部代码及资源) 目录: 一. Kafka概述 二. Kafka启动命令 三.我们为什么使用Kafka 四. Kafka数据平台中间件设计及代码解析 五. ...
- CentOS6.5修改mysql数据文件路径
1.停止mysql服务 service mysql stop 2.移动数据文件位置(保留原文件权限) cp -a /var/lib/mysql /mysqldata 3.修改/et ...