gpt4 book ai didi

ios - 解析 RSS 提要时发送到实例的无法识别的选择器

转载 作者:行者123 更新时间:2023-11-29 00:02:10 25 4
gpt4 key购买 nike

有问题的 Feed 是 https://fritchcoc.podbean.com/feed/

我的代码中有这个要解析,但每次运行它时,我都会收到以下错误消息。我试图添加异常断点,但它没有向我显示导致所有骚动的代码行。我已经花了两个小时来解决这个问题,但一点运气也没有。我在命令中将每个 NSString 都设置为 nil,以防万一 valueForChild 项中的一个出现错误,但即使全部为 nil,它们也有问题。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RSSEntry initWithBlogTitle:articleTitle:articleUrl:articleDate:articleImage:contentEncoded:]: unrecognized selector sent to instance

- (void)viewDidLoad {
[super viewDidLoad];

self.allEntries = [NSMutableArray array];
self.queue = [[[NSOperationQueue alloc] init] autorelease];
self.feeds = [NSArray arrayWithObjects:@"https://fritchcoc.podbean.com/feed/",
nil];


[self refresh];
}

- (void)refresh {
for (NSString *feed in _feeds) {
NSURL *url = [NSURL URLWithString:feed];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[_queue addOperation:request];
}

}

- (void)parseFeed:(GDataXMLElement *)rootElement entries:(NSMutableArray *)entries {
if ([rootElement.name compare:@"rss"] == NSOrderedSame) {
[self parseRss:rootElement entries:entries];
} else if ([rootElement.name compare:@"feed"] == NSOrderedSame) {
[self parseAtom:rootElement entries:entries];
} else {
NSLog(@"Unsupported root element: %@", rootElement.name);
}
}

- (void)requestFinished:(ASIHTTPRequest *)request {
[_queue addOperationWithBlock:^{
NSError *error;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:[request responseData]
options:0 error:&error];
if (doc == nil) {
NSLog(@"Failed to parse %@", request.url);
} else {
NSMutableArray *entries = [NSMutableArray array];
[self parseFeed:doc.rootElement entries:entries];

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
//int newCounter = 0;

for (RSSEntry *entry in entries) {
// newCounter++;
int insertIdx = [_allEntries indexForInsertingObject:entry sortedUsingBlock:^(id a, id b) {
RSSEntry *entry1 = (RSSEntry *) a;
RSSEntry *entry2 = (RSSEntry *) b;
return [entry1.articleDate compare:entry2.articleDate];
}];

[_allEntries insertObject:entry atIndex:insertIdx];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:insertIdx inSection:0]]
withRowAnimation:nil];
/* if (newCounter > 999) {
break;
}*/
}
}];
}
}];
}

- (void)requestFailed:(ASIHTTPRequest *)request {
NSError *error = [request error];
NSLog(@"Error: %@", error);
[self refresh];
}

- (void)parseRss:(GDataXMLElement *)rootElement entries:(NSMutableArray *)entries {
NSLog(@"Go");
NSArray *channels = [rootElement elementsForName:@"channel"];
for (GDataXMLElement *channel in channels) {
NSString *blogTitle = [channel valueForChild:@"title"];

NSArray *items = [channel elementsForName:@"item"];
for (GDataXMLElement *item in items) {
NSString *articleTitle = [item valueForChild:@"title"];
NSString *articleDateString = [item valueForChild:@"pubDate"];
NSString *theCategory = [item valueForChild:@"category"];
NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822];
NSString *articleUrl = [[[[item elementsForName: @"enclosure"] lastObject] attributeForName: @"url"] stringValue];
NSString *picture = [[[[item elementsForName: @"media:content"] lastObject] attributeForName: @"href"] stringValue];
RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:blogTitle
articleTitle:articleTitle
articleUrl:articleUrl
articleDate:articleDate
articleImage:picture
contentEncoded:nil
category:theCategory] autorelease];
if ([theCategory isEqualToString:@"Sermon"]) {
[entries addObject:entry];
}
}
}
}

最佳答案

在你的代码中你有这样的调用:

    RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:blogTitle 
articleTitle:articleTitle
articleUrl:articleUrl
articleDate:articleDate
articleImage:picture
contentEncoded:nil
category:theCategory] autorelease];

它有一个“类别”最后一个参数,但您的错误消息没有:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RSSEntry initWithBlogTitle:articleTitle:articleUrl:articleDate:articleImage:contentEncoded:]: unrecognized selector sent to instance

是否有可能您制作了一个具有“类别”的新版本 RSSEntry,但没有正确地重新编译您的一些解析代码,并且该代码仍在尝试调用旧方法(没有“类别”) ?如果是这样,就做一个产品-“清理”-“构建”,并注意编译错误和警告。

我注意到您仍然没有使用 ARC(称为“autorelease”),这向我表明这是一个非常古老的代码:)

关于ios - 解析 RSS 提要时发送到实例的无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49228700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com