iOS class methods, instance methods

Source: Internet
Author: User

Starting from yesterday, prepare the book from objective-c programming:the Big Nerd Ranch Guide and learn oc from the ground up, and improve your English reading ability by the way.

The focus of today's knowledge is on the difference between class methods and instance methods:

NSDate *now = [NSDate Date];

We say the date method is a class method. That's, 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 is a class method that sends a message to the NSDate class, which returns a value of NSDate instance pointer.

Double seconds = [now timeIntervalSince1970];

We say that timeIntervalSince1970 are 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 is an instance method that, when you execute the method, sends a message to an instance of the class that returns a value of type double.

NSDate *later = [now datebyaddingtimeinterval:100000];

Datebyaddingtimeinterval: is another instance method. This method takes one argument. You can determine the colon in the method name. This method also returns a pointer to an instance of NSDate.

Datebyaddingtimeinterval is another instance variable. This method requires a parameter. Distinguished by a colon in the method name. The method also returns a pointer to the NSDate instance.

iOS class methods, instance methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.