2014-12-28 136 views
0

最近我一直在試圖關注如何在Xcode 6測試版中製作RSS閱讀器應用程序的教程,儘管我使用的是Xcode 6.1。我碰到一條看起來是錯誤的線。Xcode - RSS閱讀器

完整的代碼是:

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")! 

它說斯威夫特Compiler Error - Expected Type

任何幫助將不勝感激。

回答

2

問題似乎是你的聲明是錯誤的。

Swift允許你通過鍵入var foo : String來強制變量爲特定類型(而不是Swift自動確定類型),你會得到一個類型爲String的變量foo。 http://www.appcoda.com/building-rss-reader-using-uisplitviewcontroller-uipopoverviewcontroller/

+0

:要刪除​​你的錯誤,任何一種類型的

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

或鍵入

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

另外,教程中,我建設在Xcode的RSS閱讀器極大的讚賞,可以在發現謝謝@Afstkla!非常感謝您的幫助! –