Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Classes/DetailTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#import "NSString+HTML.h"

typedef enum { SectionHeader, SectionDetail } Sections;
typedef enum { SectionHeaderTitle, SectionHeaderDate, SectionHeaderURL, SectionHeaderAuthor } HeaderRows;
typedef enum { SectionHeaderTitle, SectionHeaderDate, SectionHeaderURL, SectionHeaderAuthor, SectionHeaderCategories } HeaderRows;
typedef enum { SectionDetailSummary } DetailRows;

@implementation DetailTableViewController
Expand Down Expand Up @@ -85,7 +85,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
switch (section) {
case 0: return 4;
case 0: return 5;
default: return 1;
}
}
Expand Down Expand Up @@ -130,6 +130,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
case SectionHeaderAuthor:
cell.textLabel.text = item.author ? item.author : @"[No Author]";
break;
case SectionHeaderCategories:
cell.textLabel.font = [UIFont systemFontOfSize:8];
cell.textLabel.numberOfLines = 2;
cell.textLabel.text = item.categories.count ? [item.categories componentsJoinedByString:@", "] : @"[No Categories]";
break;
}
break;

Expand Down
2 changes: 2 additions & 0 deletions Classes/MWFeedItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
NSString *summary; // Description of item
NSString *content; // More detailed content (if available)
NSString *author; // Item author
NSArray *categories; // Array of categories as NSStrings (if available)

// Enclosures: Holds 1 or more item enclosures (i.e. podcasts, mp3. pdf, etc)
// - NSArray of NSDictionaries with the following keys:
Expand All @@ -57,6 +58,7 @@
@property (nonatomic, copy) NSString *summary;
@property (nonatomic, copy) NSString *content;
@property (nonatomic, copy) NSString *author;
@property (nonatomic, copy) NSArray *categories;
@property (nonatomic, copy) NSArray *enclosures;

@end
2 changes: 2 additions & 0 deletions Classes/MWFeedItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ - (id)initWithCoder:(NSCoder *)decoder {
summary = [decoder decodeObjectForKey:@"summary"];
content = [decoder decodeObjectForKey:@"content"];
author = [decoder decodeObjectForKey:@"author"];
categories = [decoder decodeObjectForKey:@"categories"];
enclosures = [decoder decodeObjectForKey:@"enclosures"];
}
return self;
Expand All @@ -73,6 +74,7 @@ - (void)encodeWithCoder:(NSCoder *)encoder {
if (summary) [encoder encodeObject:summary forKey:@"summary"];
if (content) [encoder encodeObject:content forKey:@"content"];
if (author) [encoder encodeObject:author forKey:@"author"];
if (categories) [encoder encodeObject:categories forKey:@"categories"];
if (enclosures) [encoder encodeObject:enclosures forKey:@"enclosures"];
}

Expand Down
16 changes: 15 additions & 1 deletion Classes/MWFeedParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
else if ([currentPath isEqualToString:@"/rss/channel/item/content:encoded"]) { if (processedText.length > 0) item.content = processedText; processed = YES; }
else if ([currentPath isEqualToString:@"/rss/channel/item/pubDate"]) { if (processedText.length > 0) item.date = [NSDate dateFromInternetDateTimeString:processedText formatHint:DateFormatHintRFC822]; processed = YES; }
else if ([currentPath isEqualToString:@"/rss/channel/item/enclosure"]) { [self createEnclosureFromAttributes:currentElementAttributes andAddToItem:item]; processed = YES; }
else if ([currentPath isEqualToString:@"/rss/channel/item/category"]) { if (processedText.length > 0) [self addCategory:processedText toItem:item]; processed = YES; }
else if ([currentPath isEqualToString:@"/rss/channel/item/dc:date"]) { if (processedText.length > 0) item.date = [NSDate dateFromInternetDateTimeString:processedText formatHint:DateFormatHintRFC3339]; processed = YES; }
}

Expand Down Expand Up @@ -657,6 +658,7 @@ - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
else if ([currentPath isEqualToString:@"/feed/entry/author/name"]) { if (processedText.length > 0) item.author = processedText; processed = YES; }
else if ([currentPath isEqualToString:@"/feed/entry/dc:creator"]) { if (processedText.length > 0) item.author = processedText; processed = YES; }
else if ([currentPath isEqualToString:@"/feed/entry/published"]) { if (processedText.length > 0) item.date = [NSDate dateFromInternetDateTimeString:processedText formatHint:DateFormatHintRFC3339]; processed = YES; }
else if ([currentPath isEqualToString:@"/feed/entry/category"]) { if (processedText.length > 0) [self addCategory:processedText toItem:item]; processed = YES; }
else if ([currentPath isEqualToString:@"/feed/entry/updated"]) { if (processedText.length > 0) item.updated = [NSDate dateFromInternetDateTimeString:processedText formatHint:DateFormatHintRFC3339]; processed = YES; }
}

Expand Down Expand Up @@ -923,6 +925,18 @@ - (BOOL)createEnclosureFromAttributes:(NSDictionary *)attributes andAddToItem:(M

}

// Add a category to a given item
- (BOOL)addCategory:(NSString *)category toItem:(MWFeedItem *)currentItem {
if (currentItem.categories) {
currentItem.categories = [currentItem.categories arrayByAddingObject:category];
return YES;
} else {
currentItem.categories = [NSArray arrayWithObject:category];
return YES;
}
return NO;
}

// Process ATOM link and determine whether to ignore it, add it as the link element or add as enclosure
// Links can be added to MWObject (info or item)
- (BOOL)processAtomLink:(NSDictionary *)attributes andAddToMWObject:(id)MWObject {
Expand All @@ -946,4 +960,4 @@ - (BOOL)processAtomLink:(NSDictionary *)attributes andAddToMWObject:(id)MWObject
return NO;
}

@end
@end
5 changes: 3 additions & 2 deletions Classes/MWFeedParserAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ @implementation MWFeedParserAppDelegate
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch
[window addSubview:[navigationController view]];
// Override point for customization after app launch
[window setRootViewController:navigationController];
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
return YES;
}
Expand Down
5 changes: 2 additions & 3 deletions Classes/RootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ - (void)viewDidLoad {
target:self
action:@selector(refresh)];
// Parse
// NSURL *feedURL = [NSURL URLWithString:@"http://images.apple.com/main/rss/hotnews/hotnews.rss"];
// NSURL *feedURL = [NSURL URLWithString:@"http://feeds.mashable.com/Mashable"];
NSURL *feedURL = [NSURL URLWithString:@"http://techcrunch.com/feed/"];
// NSURL *feedURL = [NSURL URLWithString:@"https://images.apple.com/main/rss/hotnews/hotnews.rss"];
NSURL *feedURL = [NSURL URLWithString:@"https://techcrunch.com/feed/"];
feedParser = [[MWFeedParser alloc] initWithFeedURL:feedURL];
feedParser.delegate = self;
feedParser.feedParseType = ParseTypeFull; // Parse feed info and all items
Expand Down
4 changes: 2 additions & 2 deletions MWFeedParser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
GCC_VERSION = com.apple.compilers.llvmgcc42;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
Expand All @@ -340,7 +340,7 @@
GCC_VERSION = com.apple.compilers.llvmgcc42;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
SDKROOT = iphoneos;
};
Expand Down
Loading