Class instantiation and method call in oc, oc instance call

Source: Internet
Author: User

Class instantiation and method call in oc, oc instance call
In the previous article, we talked about the creation of oop and classes. In the previous article, we will review this article to implement class instantiation and call public parameters and methods in the class. The implementation of the class is in. in the m file, the following is the implementation code:

/// HuiTu. m // Test // Created by Cheng Ying on. // Copyright, 2017, Cheng yingmiao. all rights reserved. // # import "HuiTu. h "@ implementation HuiTu // obtain the color-(void) GetYanse :( NSString *) yanse {_ yanse = yanse; NSLog (@" % @ ", _ yanse );} // obtain the shape-(void) GetXingZhuang :( NSString *) xingzhuang {_ xingzhuang = xingzhuang; NSLog (@ "% @", _ xingzhuang );}; // draw-(void) HuiZhi {NSLog (@ "Start Drw ");//...} @ end
Next we will go to main. call the huitu class in m: The Code is as follows: add reference # import "HuiTu. h "main {HuiTu * h = [[HuiTu alloc] init]; // The instantiation class * Pointer Points to the class [h GetYanse: @" red "]; [h HuiZhi];}
  • * H Pointer Points to this class. If you do not understand the pointer, remember to add a pointer before the class *
  • [Alloc] allocating buckets
  • Init instantiation
  • [H GetYanse: @ "red"]; The class method is also implemented here, the method on the left, and the input value on the right.
  • The result is as follows:

    20:12:28. 697389 Test [6031: 229656]Red

    20:12:28. 697403 Test [6031: 229656] Start Drw


Related Article

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: 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.