Dark Horse programmer--"Dark Horse video Notes" The function and method of OC Language Foundation

Source: Internet
Author: User

Method


1. The object method is a minus-
2. The Declaration of the object method must be written between @interface and @end
The implementation of the object method must be written between @implementation and @end
3. Object methods can only be called by objects
4. Object method collation \ Object All

Function


1. function can be written anywhere in the file (except between @interface and @end), function is file-owned
2. Function calls do not depend on the object
3. The member variable of an object cannot be accessed directly from the member variable name within the function

   1:  #import <Foundation/Foundation.h>
   2:  
   3:  @Interface Person:nsobject
   4:  @end
   5:  
   6:  @implementation Person
   7:  @end
   8:  
   9:  @Interface Car:nsobject
  Ten:  {//member variable \ instance variable
One   :      //int wheels = 4; not allowed to initialize here
  :      //static int wheels; You cannot use member variables as variables in C language arbitrarily.
  :      @ public
  :      int wheels;
  :  }
  :  
  :  -(void) run;
  :  -(void) fly;
  :  @end
  :  
+   :  int main ()
  :  {
Max   :      //wheels = ten;
  :/      *
  :      car *c = [car new];
  :      c->wheels = 4;
  :      //run ();
  28:      
  :      [C Run];
  :      * /
  31:      
  :      void test2 ();
  33:      
  :      test2 ();
  35:      
  £ º      return 0;
  Panax Notoginseng  :}
  :  
  :  @implementation Car
Max   :  
Double   :  -(void) fly
  :  {
  43:      
  :  }
  :  
*   /  *
A   :  void test2 ()
  :  {
A   :      NSLog (@ "called the Test2 function-%d", wheels);
}*/   :  
  Wuyi:  
  :  void test ()
  :  {
Si   :      NSLog (@ "called the test Function");
  :  }
  :  
  £ º  -(void) run
The   following  :{
  :      test ();
  :      NSLog (@ "%d wheels of the car ran up", wheels);
A   :  }
+   :  @end

Dark Horse programmer--"Dark Horse video Notes" The function and method of OC Language Foundation

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.