Ok, I have to admit that I am not a profi in Xcode, so I can add the whole code here, maybe this helps.
This is my AppMasterViewController. The error, new in Xcode 7.1 is in line 41. Maybe this helps.
//
// APPMasterViewController.m
// meviva
//
// Created by on 10/03/2014.
// Copyright (c) 2014 Thomas. All rights reserved.
//
#import "APPMasterViewController.h"
#import "APPDetailViewController.h"
//#import "MainTabBarController.h"
#import "RSSObject.h"
@interface APPMasterViewController () {
NSXMLParser *parser;
NSMutableArray *feeds;
NSMutableDictionary *item;
NSMutableString *title;
NSMutableString *link;
NSString *element;
NSMutableArray *currentFeeds;
RSSObject *tempRssObj;
NSMutableArray *savedFeeds;
}
@end
@implementation APPMasterViewController
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad {
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_home.png"]];
[super viewDidLoad];
currentFeeds = [[NSMutableArray alloc] init];
savedFeeds = [[NSMutableArray alloc] initWithObjects:nil];
[self loadSavedFeeds];
feeds = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:@"http://xxxxxxxxxxxxxx.blogspot.com/feeds/posts/default?alt=rss"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return feeds.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
RSSObject * rssObj = [[RSSObject alloc] init];
rssObj = [currentFeeds objectAtIndex:indexPath.row];
if(!rssObj.isNewFeed)
cell.textLabel.textColor = [UIColor grayColor];
else
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: @"title"];
return cell;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
element = elementName;
if ([element isEqualToString:@"item"]) {
item = [[NSMutableDictionary alloc] init];
title = [[NSMutableString alloc] init];
link = [[NSMutableString alloc] init];
tempRssObj = [[RSSObject alloc] init];//thuan add
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"item"]) {
[item setObject:title forKey:@"title"];
[item setObject:link forKey:@"link"];
[feeds addObject:[item copy]];
tempRssObj.link = link;
tempRssObj.title = title;
tempRssObj.isNewFeed = TRUE;
[currentFeeds addObject: tempRssObj];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([element isEqualToString:@"title"]) {
[title appendString:string];
} else if ([element isEqualToString:@"link"]) {
[link appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[self.tableView reloadData];
[self updateBadgeValue];
}
-(void) updateBadgeValue{
[self markNewFeeds];
int countNewFeeds = [self getCountNewFeeds];
UINavigationController* parent = (UINavigationController*)[self parentViewController];
if (countNewFeeds>0) {
parent.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d", countNewFeeds];
}
else
parent.tabBarItem.badgeValue = nil;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *string = [feeds[indexPath.row] objectForKey: @"link"];
[[segue destinationViewController] setUrl:string];
RSSObject * rssObj = [[RSSObject alloc] init];
rssObj = [currentFeeds objectAtIndex:indexPath.row];
rssObj.isNewFeed = FALSE;
if (![self checkExistObject:rssObj]) {
[savedFeeds addObject:rssObj];
[self saveFeeds];
[self updateBadgeValue];
[self loadSavedFeeds];
[self.tableView reloadData];
}
}
}
-(int) getCountNewFeeds{
int count = 0;
for (int i=0; i< currentFeeds.count; i++) {
tempRssObj = [currentFeeds objectAtIndex:i];
if (tempRssObj.isNewFeed) {
count ++;
}
}
return count;
}
- (void)saveFeeds{
RSSObject * temp =[[RSSObject alloc] init];
temp.title =@"ABC";
temp.link = @"link";
temp.isNewFeed = TRUE;
NSData *customObjectData = [NSKeyedArchiver archivedDataWithRootObject:savedFeeds];
[[NSUserDefaults standardUserDefaults] setObject:customObjectData forKey:@"SAVED_FEEDS"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)loadSavedFeeds {
// RSSObject * temp;
NSData *customObjectData = [[NSUserDefaults standardUserDefaults] objectForKey:@"SAVED_FEEDS"];
if (customObjectData) {
savedFeeds = [NSKeyedUnarchiver unarchiveObjectWithData:customObjectData];
}
// // NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// savedFeeds = [defaults objectForKey:@"SAVED_FEEDS"];
}
-(void) markNewFeeds{
RSSObject * currentObj = [[RSSObject alloc] init];
RSSObject * savedObj = [[RSSObject alloc] init];
for (int i=0; i< currentFeeds.count; i++) {
currentObj = [currentFeeds objectAtIndex:i];
for (int j=0; j<savedFeeds.count; j++) {
savedObj = [savedFeeds objectAtIndex:j];
if ([currentObj.link isEqualToString:savedObj.link] && [currentObj.title isEqualToString: savedObj.title]) {
currentObj.isNewFeed = FALSE;
}
}
}
}
-(BOOL) checkExistObject:(RSSObject *)rssObj{
for (RSSObject * temp in savedFeeds) {
if ([temp isEqual:rssObj]) {
return TRUE;
}
}
return FALSE;
}
@end
Next I have a View for the Details of each feed
#import "APPDetailViewController.h"
@implementation APPDetailViewController
#pragma mark - Managing the detail item
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *myURL = [NSURL URLWithString: [self.url stringByAddingPercentEscapesUsingEncoding:
NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:myURL];
[self.webView loadRequest:request];
}
@end
And last but not least the RSSObject
#import "RSSObject.h"
#define RSS_LINK_KEY @"RSS_LINK_KEY"
#define RSS_TITLE_KEY @"RSS_TITLE_KEY"
#define RSS_IS_NEW_KEY @"RSS_IS_NEW_KEY"
@implementation RSSObject
@synthesize link;
@synthesize title;
@synthesize isNewFeed;
- (id)initWithCoder:(NSCoder *)decoder {
self = [super init];
if(self) {
self.link = [decoder decodeObjectForKey:RSS_LINK_KEY];
self.title = [decoder decodeObjectForKey:RSS_TITLE_KEY];
self.isNewFeed = [decoder decodeBoolForKey:RSS_IS_NEW_KEY];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:self.link forKey:RSS_LINK_KEY];
//dereferance the pointer to persist the value
[encoder encodeObject:self.title forKey:RSS_TITLE_KEY];
[encoder encodeBool:self.isNewFeed forKey:RSS_IS_NEW_KEY];
}
@end