Statements and definitions such as "Good Programmer's note sharing" obj-c

Source: Internet
Author: User

<a href= "http://www.goodprogrammer.org/" target= "blank" >ios training </A>------My obj-c language notes, looking forward to communicating with you!

As a result of the basic test, the obj-c still do not know very well, do a step confused (in fact, I think there will be only C related problems-_-#), there are some classes of inheritance, declaration, definition aspect is a problem, because before the C + + to object-oriented have a certain understanding, First look at the information in advance to see objc-c this piece of knowledge.

 Declaration of the class:
1 #import<Foundation/Foundation.h>2 3 @interfacePerson:nsobject4 {5 @public:6 intAge ; 7 }8-(void) func;9 @end
implementation of the class: Ten #import"Person.h" One A @implementation Person --(void) func{ -NSLog (@"I ' m very hungry now"); the } - @end

Declaration: @interface Class Name: Parent class Name {} @end

Definition: @implement {} @end

NSObject is a direct or indirect parent class of any class

Member variable access permission modifiers: @public, @protected(default), @private

Member Methods and class methods: "-" is decorated as a member method, "+" is a class method (class methods cannot contain instance variables, or direct-to-compile-time errors)

When you want to expose a member method, declare it between the @interface class name: Parent class Name {} @end, and be able to call outside the class

Common errors:

(1) @interface @end and @implementation @end cannot be nested with

(2) Only the declaration of the class has no implementation of the class

(3) Missing write @end

(4) member variable not written in {}

(5) The declaration of the method is written in {}

(6) method cannot be called like a function

(7) member variables and methods can not be modified with static and other keywords, do not confuse the C language ( static variable generation method: The @interface class Name: The parent class name {} @end the member variable is static decorated, You need to declare a global static variable in the @implement @end implementation file, and then write the Get method and set method of the static variable to be called outside the class, so that the static variable can be generated.

(8) The implementation of the class can be written behind the Mian function, as long as there is a declaration before use can

Statements and definitions such as "Good Programmer's note sharing" obj-c

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.