2

I'm working on a project that parses an rss feed for each article's title, description and link. I need to then append the link with a string @"?f=m" I'm having trouble figuring out where to start. I'm new to IOS programming. I think the file I need to manipulate is here:

-(void)viewDidAppear:(BOOL)animated
{

RSSItem* item = (RSSItem*)self.detailItem;
self.title = item.title;
webView.delegate = self;

NSURLRequest* articleRequest = [NSURLRequest requestWithURL: item.link];


webView.backgroundColor = [UIColor clearColor];
[webView loadRequest: articleRequest];
}

But it could also be here:

-(void)fetchRssWithURL:(NSURL*)url complete:(RSSLoaderCompleteBlock)c
{


dispatch_async(kBgQueue, ^{

    //work in the background
    RXMLElement *rss = [RXMLElement elementFromURL: url];
    RXMLElement* title = [[rss child:@"channel"] child:@"title"];
    NSArray* items = [[rss child:@"channel"] children:@"item"];

    NSMutableArray* result = [NSMutableArray arrayWithCapacity:items.count];

    //more code
    for (RXMLElement *e in items) {

        //iterate over the articles
        RSSItem* item = [[RSSItem alloc] init];
        item.title = [[e child:@"title"] text];
        item.description = [[e child:@"description"] text];
        item.link = [NSURL URLWithString: [[e child:@"link" ] text ]] ;
        [result addObject: item];
    }

    c([title text], result);
});

}

Any help is sincerely appreciated.

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
kpd
  • 23
  • 2

1 Answers1

1

You simply append the parameter as below:

NSString *modifiedString = [NSString stringWithFormat:@"%@%@",[item.link absoluteString],@"?f=m"];
NSURL *modifiedUrl = [NSURL URLWithString:modifiedString];

Now use modifiedUrl instead of item.link

manujmv
  • 6,450
  • 1
  • 22
  • 35
  • Since you are appending a string literal, why use `stringWithFormat:`? Why not simply use `NSString *modifiedString = [[item.link absoluteString] stringByAppendingString:@"?f=m"];`. – rmaddy Jun 26 '13 at 04:17
  • @rmaddy: thx maddy. you can also use that. but i normally using this method and i couldnt find any huge difference between them. – manujmv Jun 26 '13 at 04:27
  • It works. Just remember that `stringWithFormat:` is much less efficient than simple string appending. For one line like this it doesn't really matter. The other option would be to replace the second `%@` in the format with the actual text since it is a literal. – rmaddy Jun 26 '13 at 04:29
  • Thanks very much all, I sincerely appreciate your help. Great learning experience. – kpd Jun 26 '13 at 16:37