标签:
从昨天开始准备从Objective-C Programming: The Big Nerd Ranch Guide这本书入手,从头扎实地学习一下OC,顺便提高一下英文阅读能力。
今天的知识重点在于类方法和实例方法的区别:
NSDate *now = [NSDate date];
We say that the date method is a class method. That is, you cause the method to execute by sending a message to the NSDate class. The date method returns a pointer to an instance of NSDate.
date是一种类方法,你发送消息的目标是NSDate类,该方法返回值为一个NSDate的实例指针。
double seconds = [now timeIntervalSince1970];
We say that timeIntervalSince1970 is an instance method. You cause the method to execute by sending a message to an instance of the class. The timeIntervalSince1970 method returns a double.
timeIntervalSince1970是一种实例方法,你执行该方法时发送消息的目标是类的一个实例,该方法返回值为一个double型变量。
NSDate *later = [now dateByAddingTimeInterval:100000];
dateByAddingTimeInterval: is another instance method. This method takes one argument. You can determine this by the colon in the method name. This method also returns a pointer to an instance of NSDate.
dateByAddingTimeInterval是另一种实例变量。该方法需要一个参数。通过方法名中的冒号区分。该方法同样返回一个指向NSDate实例的指针。
标签:
原文地址:http://www.cnblogs.com/JoJosBizarreAdventure/p/4581457.html