类的属性,初始化函数,结束函数

#import <Foundation/Foundation.h>

//声明了一个类Init 

@interface Init : NSObject

{

    int a;

    int b;

    NSString *name;

}

 

@propertyint a,b;//设置函数的默认属性设置

@end

 

@implementation Init

 

@synthesize a,b;

 

-(id)init//默认的初始化函数

{

    self=[super init];  //父类的初始化

    if (self) {

        a=19;

        b=89;

        name=[[NSStringalloc] initWithFormat:@"就像秋风带走我的思念,我的梦"];

        NSLog(@"这时初始化函数");

    }

    returnself;

}

 

-(void) dealloc//默认的结束函数

{

    NSLog(@"这时最后输出的") ;

    [name release];

    [super dealloc];

}

 

 

@end

int main(int argc, const char * argv[])

{

 

    @autoreleasepool {

        Init *aa=[[Init alloc] init];  //声明指针

        [aa release];释放aa对象

        // insert code here...

        NSLog(@"Hello, World!");

    

    }

    return 0;

}

结果是:

原文地址:https://www.cnblogs.com/flyingdreaming/p/classandinitanddealloc.html