Sunday, 15 May 2011

ios - how to connect RSS feed with swift -


I want to make an application on the news about I decided to use RSS feeds but did not somehow RSS feed .

Here is my code I

This is my viewDidload function

  Feeds = [] var url: NSURL = NSURL (string: "https://www.apple.com/ Main / rss / hotnews / hotnews.rss ")! Parser = NSXMLParser (Content of URL: URL)! parser.delegate = self parser.shouldProcessNamespaces = false parser.shouldReportNamespacePrefixes = false parser.shouldResolveExternalEntities = false parser.parse ()  

This is my didStartElement work.

  function parser (parser: NSXMLParser!, DidStartElement ElementName: string!, NamespaceURI: String!, QualifiedName QName: string! Characteristics attributeDict: [NSObject: AnyObject]!) {Element feed properties that (Element as element = NSString of elementName //) .isEqualToString ("item") {elements = NSMutableDictionary.alloc () element = [:] ftitle = NSMutableString.alloc () ftitle = "" link = NSMutableString.alloc ( ) link = "" fdescription = NSMutableString.alloc () fdescription = ""}  

this is my didEndElement

  function parser (parser: NSXMLParser!, DidEndElement elementName: string !, namespaceURI: string !, perfect Name qName: string!) {// process feed element if (elementName as NSString) .isEqualToString ("item") {if the subtitle! = "" {Elements.setObject (fortitle, forKey: "title")} If the link! = "" {Elements.setObject (link, forKey: "link")} if fdescription! = "" {Elements.setObject (fdescription, forKey: "decription")} feeds. AddObject (elements)}}  

This is my foundCharacter function

  Function parser (parser: NSXMLParser !, foundCharacters string: string) {if element.isEqualToString ("title") {ftitle.appendString (string)} else if element.isEqualToString ("link") {link.appendString (string)} And if element.isEqualToString ("description") {fdescription.appendString (string)}}  

This is my cellularoutexpace function

  cell = table view. DeitueReusableCellWithIdentifier ("cell", forIn DexPath: indexPath) as UITableViewCell // cell ... text.textLabel? .text = (feeds.objectAtIndex (indexPath.row) .objectForKey ("tittle") as string) cell.detailTextLabel? .numberOfLines = 3 cell DetailTextLabel? .text = (feeds.objectAtIndex (indexPath.row) .objectForKey (in the form of a "description") string) return cell  

Am I missing something? Any suggestions?


No comments:

Post a Comment