Xcode - RSS阅读器

时间:2014-12-28 01:36:43

标签: ios xcode rss feed xcode6.1

最近我一直在尝试按照Xcode 6测试版制作RSS阅读器应用程序的教程,尽管我使用的是Xcode 6.1。我遇到了一条看似错误的线。

完整的代码是:

import UIKit

class TableViewController: UITableViewController, NSXMLParserDelegate {

var parser = NSXMLParser()
var feeds = NSMutableArray()
var elements = NSMutableDictionary()
var element = NSString()
var ftitle = NSMutableString()
var link = NSMutableString()
var fdescription = NSMutableString()

override func viewDidLoad() {
    super.viewDidLoad()

    feeds = []
    var url: = NSURL(string: "http://www.mentonegrammar.net/rss/news")!
    parser = NSXMLParser(contentsOfURL: url)
    parser.delegate = self
    parser.shouldProcessNamespaces = false
    parser.shouldReportNamespacePrefixes = false
    parser.shouldResolveExternalEntities = false
    parser.parse()
}

func parser(parser: NSXMLParser!, didStartElement elementName: String!, 
            namespaceURI: String!, qualifiedName qName: String!, 
            attributes attributeDict: [NSObject : AnyObject]!) {

    element = elementName

    // instantlate

}

func parser(parser: NSXMLParser!, didEndElement elementName: String!, 
            namespaceURI: String!, qualifiedName qName: String!) {

}

func parser(parser: NSXMLParser!, foundCharacters string: String!) {

}

func parserDidEndDocument(parser: NSXMLParser!) {

}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 0
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 0
}

/*
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as UITableViewCell

    // Configure the cell...

    return cell
}
*/



}

错误是:

var url: = NSURL(string: "http://www.mentonegrammar.net/rss/news")!

它说Swift Compiler Error - Expected Type

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

问题似乎是你的声明是错误的。

Swift允许您通过键入var foo : String将变量强制为特定类型(而不是Swift自动确定类型),您将获得名为foo的变量,类型为String。要删除错误,请键入

var url = NSURL(string: "http://www.mentonegrammar.net/rss/news")!

或输入

var url : NSURL = NSURL(string: "http://www.mentonegrammar.net/rss/news")!

此外,我非常感谢在xCode中构建RSS阅读器的教程:http://www.appcoda.com/building-rss-reader-using-uisplitviewcontroller-uipopoverviewcontroller/