建立一个Book类
Book.h
#import <Foundation/Foundation.h>
{
NSString *_title;
NSSInteger _pageNum;
}
- (void)showDetail;
- (instancetype)initWithTitle:(NSString *)title withPageNum:(NSInteger)pageNum;
@end
Book.m
#import "Book.h"
@implementation Book
- (instancetype)initWithTitle:(NSString *)title withPageNum:(NSInteger)pageNum
{
if(self = [super init])
{
_title = title;
_pageNum = pageNum;
}
return self;
}
- (void)showDetail
{
NSLog(@"书名:%@ 页数:%ld",_title,_pageNum);
}
@end
main.m
#import <Foundation/Foundation.h>
#import "Book.h"
int main(int argc, const char *argv[])
{
@autoreleasepool
{
Book *book = [[Book alloc]initWithTitle:@"三体" withPageNum:100];
[book showDetail];
}
return 0;
}