Objective c Book没有可见的@interface声明选择器

Objective c Book没有可见的@interface声明选择器,objective-c,Objective C,不明白为什么,一切看起来都很好;(但是我在simplebookmanager.m中没有为Book声明选择器“initWithAuthor”的可见@interface。我也尝试关闭Xcode并再次运行,但没有成功 书 #import<Foundation/Foundation.h> @interface Book : NSObject @property NSString *author; @property NSString *titel; @property NSInteger

不明白为什么,一切看起来都很好;(但是我在simplebookmanager.m中没有为Book声明选择器“initWithAuthor”的可见@interface。我也尝试关闭Xcode并再次运行,但没有成功

#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;
#导入
@接口书:NSObject
@属性字符串*作者;
@属性NSString*titel;
@房地产价格;
@属性NSString*isbn;
@属性字符串*课程;
-(id)initWithAuthor:(NSString*)作者
titel:(NSString*)aTitel
价格:(NSInteger)aPrice
isbn:(NSString*)anIsbn
课程:(NSString*)一门课程;
@结束
book.m
#导入“Book.h”
@实施手册
-(id)initWithAuthor:(NSString*)作者
titel:(NSString*)aTitel
价格:(NSInteger)aPrice
isbn:(NSString*)anIsbn
课程:(NSString*)A课程{
self=[super init];
如果(自我){
_作者=[A作者副本];
_滴度=[aTitel副本];/???
_价格=价格;
_isbn=[anIsbn副本];
_课程=[A课程副本];
}
回归自我;
}
@结束
------------------------------------------------------------
#导入“SimpleBookManager.h”
#导入“BookManagerProtocol.h”
#导入“Book.h”
@接口SimpleBookManager()
@属性NSMutableArray*所有书籍;
@结束
SimpleBookManager.m
@实现SimpleBookManager
-(id)init{
self=[super init];
如果(自我){
_allBooks=[[NSMutableArray alloc]init];

Book*b1=[[Book alloc]initWithAuthor:@“Ben”];此处调用的方法:

Book *b1 = [[Book alloc]initWithAuthor :@"Ben"];
与此方法不同:

-  (id)initWithAuthor:(NSString *)aAuthor
                titel:(NSString*)aTitel
                price:(NSInteger)aPrice
                 isbn:(NSString*)anIsbn
               course:(NSString*)aCourse;
您需要提供方法的所有参数来调用正确的方法,从而避免警告

例如:

Book *b1 = [[Book alloc]initWithAuthor:@"Ben"
                                 titel:@"Ford Escort Haynes Manual"
                                 price:11
                                  isbn:@"AAXXEE22"
                                course:@"Yup"];
你的:

应该是:

Book *b1 = [[Book alloc]initWithAuthor:@"authorName" titel:@"title" price:123 isbn:@"123" course:@"course"];

您的答案不正确;您在Objective-C中除了varargs之外不使用逗号分隔参数。@trojanfoe当然!不敢相信我写了这个。我每天8小时编写obj-C代码,我写了这样的东西。太棒了。我学到了一个教训,在做其他事情的同时不要回答问题。我站在正确的位置,我编辑了我的答案回答。对你的评论投了赞成票。谢谢,伙计。没问题,我知道这是怎么回事-就像你忘了怎么拼写一个单词一样。然后对你的答案投了赞成票;-)
Book *b1 = [[Book alloc]initWithAuthor :@"Ben"];
Book *b1 = [[Book alloc]initWithAuthor:@"authorName" titel:@"title" price:123 isbn:@"123" course:@"course"];