以前曾问过这个问题,但从来没有问过我的具体问题:
@property (readonly, copy, nonatomic) NSString *blogName;
@property (readonly, copy, nonatomic) NSString *blogEmail;
@property (strong, nonatomic) id<BlogParserDelegate> delegate; // This is my first problem
@property (strong, nonatomic) NSDictionary *blogSocialNetworkUserNames; // This is my second problem
@property (readonly, copy, nonatomic) NSString *blogLogoImageLink;
@property (readonly, copy, nonatomic) NSString *blogWebsite;
我不知道如何在Swift中实现两个标记的属性,我尝试了一些事情,这是我最后一次尝试不成功:
@NSCopying var blogSocialNetworkUserNames : NSDictionary!
var blogLogoImageLink : String!
我得到的错误是:
Type 'WordPressParser' does not conform to protocol 'BlogParserProtocol'
有什么想法吗?
谢谢!
EDIT添加了所有代码:
协议:
@protocol BlogParserProtocol <NSObject>
@required
#pragma mark Properties
@property (readonly, copy, nonatomic) NSString *blogName;
@property (readonly, copy, nonatomic) NSString *blogEmail;
@property (strong, nonatomic) id<BlogParserDelegate> delegate;
@property (strong, nonatomic) NSDictionary *blogSocialNetworkUserNames;
@property (readonly, copy, nonatomic) NSString *blogLogoImageLink;
@property (readonly, copy, nonatomic) NSString *blogWebsite;
#pragma mark init methods
-(instancetype)initWithBlogName:(NSString*)blogName;
#pragma mark SFARSSParserProtocol methods
-(BOOL)isReachable;
-(void)readRSSAtURL:(NSString *)URL;
-(void)getCommentsFromArticleId:(NSString*)articleId;
-(void)addComment:(NSString*)comment
toArticleId:(NSString*)articleId;
@end
符合协议的类:
class WordPressParser: NSObject, BlogParserProtocol {
var blogName : String!
var blogEmail : String!
var delegate : AnyObject!
var blogSocialNetworkUserNames : NSDictionary!
var blogLogoImageLink : String!
var blogWebsite : String!
required init!(blogName: String!) {
}
func isReachable() -> Bool {
return true
}
func readRSSAtURL(URL: String!) {
}
func getCommentsFromArticleId(articleId: String!) {
}
func addComment(comment: String!, toArticleId articleId: String!) {
}
}
错误:
iPhone/ProjectName/WordPressParser.swift:11:1: Type 'WordPressParser' does not conform to protocol 'BlogParserProtocol'
答案 0 :(得分:0)
当您实现所有必需的协议方法时,大多数情况下此错误都将消失。只需在WordPressParser
类中编写所有必需的方法,然后尝试构建应用程序。它应该是成功的。