Object-c-Definition of class

Source: Internet
Author: User

Http://www.cnblogs.com/zhangweia/archive/2011/11/01/2231549.html

1. The document is divided into . h: Defines the interface, its properties, and the method description. . M: is the implementation class.

2, the user's class is generally derived from NSObject, the class name is capitalized, the instance name is lowercase.

3. attributes : Defined within interface, modifier, @priavte, @protected (default), @public

4, method : Define the former "-" represents the instance method, "+" represents the class method.

5, The type is to add ().

--------------------------------------------------------------------------------------

1.

Format of the header file:

#import <Foundation/Foundation.h>

@interface Myclass:nsobject

{
int numerator;
int denominator;
}
-(void) print;
-(void) Setnumberator: (int) n;
-(void) Setdenominator: (int) D;
@end

The format implemented by the class:

#import "Myclass.h"

@implementation MyClass

-(void) print
{
NSLog (@ "Hello zwh!");
NSLog (@ "%i/%i", numerator,denominator);

}
-(void) Setnumberator: (int) n
{
Numerator = n;

}
-(void) Setdenominator: (int) d
{
denominator = D;

}
@end

Object-c-Definition of class

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.