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 This is my didStartElement work. this is my didEndElement This is my foundCharacter function This is my cellularoutexpace function Am I missing something? Any suggestions?
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 ()
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 = ""}
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)}}
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)}}
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
No comments:
Post a Comment