终于上课了 感觉看了两天书都没什么屌用 不过还是比没看然后上课更熟悉点
动手敲代码记忆能力还是比看书印象深点
今天讲了类的。。。反正一大堆 很随意 都是看过的 但是用起来还是有点不会 嗯
@autoreleasepool
自动释放池
自动释放池技术提供一种机制,可以让我们将对象的所有权释放,但是不会
导致对象马上被清理。
通常我们不需要建立自己的自动释放池。在OC中,以后需要在main函数中创建对象都在
@autoreleasepool 中创建,让它自动来帮我们管理对象的所有权释放。
@implementation 和 @end 实现文件的开始和结束,在其中实现接口文件中声明的方法
创建和使用对象Student *stu = [[Student alloc]init];
//或者
Student *stu1 = [Student alloc];
stu1 = [stu1 init];
//或者
Student *stu2 = [Student new];
OC创建对象的语法;
类名 *对象名 = [[类名 alloc]init];
或者
类名 *对象名 = [类名 new];
alloc 对对象动态分配内存地址
init 在内存中填上初始值
new 为alloc 和 init 简写
如何给类中的属性赋值以及调用类中方法
stu ->_name = @"垃圾";
[stu sayHello];
NSLog(@"student->name = %@",stu->_name);
stu->_age = 15;
NSString *result = [stu eatLunch];
NSLog(@"%@",result);
手动创建一个类
@interface Teacher : NSObject
{
@public
NSString *_name;
}
-(void)classBegin;
@end
//相当于一个实现文件
@implementation Teacher
-(void)classBegin{
NSLog(@"%@ say class begin",_name);
}
@end