Chinaunix首页 | 论坛 | 博客
  • 博客访问: 50614
  • 博文数量: 34
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 297
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-09 10:52
文章分类

全部博文(34)

文章存档

2015年(23)

2014年(11)

我的朋友

分类: iOS平台

2015-03-26 20:28:44

1.自动释放池是OC里面的一种内存自动回收机制

一般可以将一些临时变量添加到自动释放池里,统一回收释放

当自动释放池销毁时,池里面的对象就会调用一次release方法

 

2.发送一条autorelease,就会把对象舔到最近的自动释放池中,

栈顶的释放池,栈是先进后出

 

3.//代表创建一个自动释放池

@autoreleasepool {

        


}



4.autorelease 不会改变计数器


5.快速创建对象的方法

+(id)student{


    Student *stu = [[[Student allocinitautorelease];

    

    return stu;



}


+(id)studentWithAge:(int)no{

    

    Student *stu = [[[Student allocinitautorelease];

    

    stu.no = no;

    

    return stu;

    


}



6.自带的类不需要管理内存,类里面已经处理完了。


7.不要把大量循环操作里面创建对象的语句放在自动释放池中间,这样会造成内存峰值上升

不要把大的内存放在池子里,会占系统内存。


8.Category

可以动态的为某个类添加新方法,仅仅是方法

@interface Student (Stu)

代表Stu是Student的分类


9.分类只能扩展方法,这里面不允许写新的成员变量

使用与团队合作


//  Student+Stu.h


#import "Student.h"


@interface Student (Stu)


-(void)fun;



@end


//  Student+Stu.m


#import "Student+Stu.h"


@implementation Student (Stu)


-(void)fun{


    NSLog(@"fun方法");

}



@end


#import 

#import "Student.h"

#import "Student+Stu.h"


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

    @autoreleasepool {

        

        Student *st = [[Student allocinit];

        

        [st fun];

        

    }

    return 0;


}

10.可以给系统自带的一些类,添加一些方法。

@implementation NSString (ST)


+(void)ss{


    NSLog(@"ss");


}



@end


11.@interface @implementation 在一个文件中可以重复出现,他只是起到声明和实现的作用

@interface Student : NSObject


-(void)fun;


@end


@interface Student (abc)


-(void)fun1;



@end


@implementation Student


-(void)fun{


    NSLog(@"fun");

}


@end


@implementation Student(abc)


-(void)fun1{

    

    NSLog(@"fun1");

}



@end

阅读(525) | 评论(0) | 转发(0) |
0

上一篇:OC入门篇7

下一篇:OC入门篇9

给主人留下些什么吧!~~