Objective-c (2)

Source: Internet
Author: User

Objective-c

Class, Object, method

The actual variable is an instance of the class.

The actions that an instance can perform are called methods.

[Classorinstance Method];

Defining classes

@interface Classname:superclass

Define method as interface

@end

Class implementation

@implementation Class {

Variable

}

Methods

@end

Myfraction = [[Fraction alloc] init];



Ex

#import <Foundation/Foundation.h>

//#import "Fraction1.h"

---------*.h

@interface Fraction: nsobject

-(void) print;

-(void) Setnumerator: (int) n;

-(void) Setdenominator: (int) D;

@end

---------*.M

@implementation Fraction {

int numerator;

int denominator;

}

-(void) Print {

NSLog(@ "%i/%i", numerator, denominator);

}

-(void) Setnumerator: (int) n {

numerator = n;

}

-(void) Setdenominator: (int) d {

Denominator = D;

}


@end


int Main (int argc, const Char * argv[]) {

@autoreleasepool {

fraction *myfraction;

Myfraction = [fraction alloc];

Myfraction = [myfraction init];

[Myfraction setnumerator: 1];

[Myfraction setdenominator: 3];

[Myfraction print];

}

return 0;

}


@property @interface

@sysnthesize @implementation


self = this;

@class


Inheritance and overrides

Abstract

Polymorphic

is* to judge

@try {

}

@catch) NSException * ex) {

}

@finally

@throw

@protected

@private

@public

@package

Enum enum

typedef

The tenth chapter is finished.

Objective-c (2)

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