首页 > 其他分享 >OC之【@class】

OC之【@class】

时间:2022-12-09 15:04:19浏览次数:41  
标签:end OC class Book Student dealloc import book

如果是继承某个类,就要导入类的头文件
@class

book.h文件:
#import <Foundation/Foundation.h>
Book : NSObject
int price;
@end

文件:
"Book.h"

Book
- (void)dealloc {
NSLog(@"Book被销毁了");

super dealloc];
}
@end

student.h文件:
#import <Foundation/Foundation.h>
Book;
@interface Student : NSObject
Book
}
Book *book;
@end

student.m文件:
#import "Student.h"
"Book.h"
Student

- (void)setBook:(Book
if (_book
_book release];
_book = [book retain];

// [book retain];
// _book = book;
}
}

- (Book
return _book;
}

- (void)dealloc {
// self.book = nil;

// [self setBook:nil];

_book release];
super dealloc];
}
@end

标签:end,OC,class,Book,Student,dealloc,import,book
From: https://blog.51cto.com/u_15907570/5925311

相关文章

  • OC之【深拷贝(mutableCopy)和浅拷贝(copy)】
    文件#import<Foundation/Foundation.h>#import"Student.h"#import"GoodStudent.h"//copy语法的目的:改变副本的时候,不会影响到源对象字符串的拷贝(深拷贝)//深拷贝:内容......
  • OC之【NSNumber的使用】
    #import<Foundation/Foundation.h>void//将int类型的10包装成一个NSNumber对象NSNumber*number=[NSNumbernumberWithInt:10];NSLog(@"number=%@",number);......
  • OC之【NSDictionary详解】
    main.m文件#import<Foundation/Foundation.h>#import"Student.h"字典的初始化void//NSDictionary是不可变的NSDictionary*dict=[NSDictionarydictionaryWit......
  • OC之【c语言结构体】
    <stdio.h>void//这个机构只能在函数内部使用//定义一个名为Student的结构体类型structintage;//年龄char*name;//姓名floatheight;//身高};......
  • OC之【NSMutableDictionary的使用】
    main.m文件#import<Foundation/Foundation.h>#import"Student.h"可变字典的使用void//创建一个空的字典NSMutableDictionary*dict=[NSMutableDictionarydicti......
  • OC之【NSValue的使用】
    #import<Foundation/Foundation.h>voidCGPointpoint=CGPointMake(10,10);//将结构体变量包装成一个对象NSValue*value=[NSValuevalueWithPoint:point];......
  • OC之【enum枚举】
    void//定义一种枚举类型enum//定义一个枚举变量senumSeasons=winter;}void//定义枚举类型的同时定义一个枚举变量senumSeason{spring,summer,......
  • OC之【NSDate使用】
    #import<Foundation/Foundation.h>日期创建void//date方法返回的就是当前时间(now)NSDate*date=[NSDatedate];//now:21:09:40//date:21:09:50......
  • OC之【内存管理】
    Student@synthesizeage=_age;//在xcode4.5以上环境下可以省略-(void)dealloc{@"%@被销毁了",self);super//一定要调用super的dealloc方法,而且最好放在最......
  • OC之【NSObject使用】
    main.m文件#import<Foundation/Foundation.h>#import"Student.h"#import"Person.h"常用方法voidStudent*stu=[[[Studentalloc]init]autorelease];//isKin......