Graphics Programs Reference
In-Depth Information
// Now only return YES if the links are equal.
return [[self link] isEqual:[object link]];
}
In RSSChannel.m , begin implementing addItemsFromChannel: so that it adds all
items from another channel if there are no duplicates.
- (void)addItemsFromChannel:(RSSChannel *)otherChannel
{
for (RSSItem *i in [otherChannel items]) {
// If self's items does not contain this item, add it
if (![[self items] containsObject:i])
[[self items] addObject:i];
}
}
Even though you do not use RSSItem 's isEqual: method explicitly, NSArray 's
containsObject: does. The containsObject: method sends isEqual: to
every object within the array, and if one responds YES , then containsObject: also
returns YES . By inverting the return value of containsObject: , addItem-
sFromChannel: will only add an item if it doesn't already have it.
Next, the RSSChannel needs to preserve the order of its items. The order of items
should be dictated by when the item was posted - the newer an item is, the higher it
should appear on the list. The post date of an item is available in the RSS feed, but
RSSItem doesn't currently collect that data. Let's change that. In RSSItem.h , declare a
new property to hold the post date.
@property (nonatomic, strong) NSDate *publicationDate;
In RSSItem.m , synthesize this property and have the XML parsing methods seek out the
appropriate element and put it into this property.
@synthesize publicationDate;
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqual:@"title"]) {
currentString = [[NSMutableString alloc] init];
[self setTitle:currentString];
}
else if ([elementName isEqual:@"link"]) {
currentString = [[NSMutableString alloc] init];
[self setLink:currentString];
Search WWH ::




Custom Search