不明白为什么,一切看起来都很好;(但我没有可见的@interface for Book 在 simplebookmanager.m 中声明选择器“initWithAuthor”我也尝试关闭 Xcode 并再次运行但没有工作
书本.h
#import<Foundation/Foundation.h>
@interface Book : NSObject
@property NSString *author;
@property NSString *titel;
@property NSInteger price;
@property NSString *isbn;
@property NSString *course;
- (id)initWithAuthor:(NSString *)aAuthor
titel:(NSString*)aTitel
price:(NSInteger)aPrice
isbn:(NSString*)anIsbn
course:(NSString*)aCourse;
@结尾
book.m
#import "Book.h"
@implementation Book
-(id)initWithAuthor:(NSString *)aAuthor
titel:(NSString*)aTitel
price:(NSInteger)aPrice
isbn:(NSString*)anIsbn
course:(NSString*)aCourse {
self = [super init];
if (self) {
_author = [aAuthor copy];
_titel = [aTitel copy]; // ???
_price = aPrice;
_isbn = [anIsbn copy];
_course = [aCourse copy];
}
return self;
}
@end
------------------------------------------------------------
#import "SimpleBookManager.h"
#import "BookManagerProtocol.h"
#import "Book.h"
@interface SimpleBookManager()
@property NSMutableArray *allBooks;
@end
SimpleBookManager.m
@implementation SimpleBookManager
-(id)init {
self = [super init];
if (self) {
_allBooks = [[NSMutableArray alloc] init];
Book *b1 = [[Book alloc]initWithAuthor :@"Ben"]; <---- got error in this part
}
return self;
}
@end
---------------------------------------------------------
SimpleBookManager.h
#import <Foundation/Foundation.h>
#import "BookManagerProtocol.h"
#import "Book.h"
@interface SimpleBookManager : NSObject<BookManagerProtocol>
@end