Reputation: 53
After migrating to Swift2 getting following error: .alloc() is unavailable in Swift: Use object initializers instead. Any help appreciated. Thank you
func parser(parser: NSXMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
element = elementName
if (element as NSString).isEqualToString("item") {
elements = NSMutableDictionary.alloc()
elements = [:]
ftitle = NSMutableString.alloc()
ftitle = ""
link = NSMutableString.alloc()
link = ""
fdescription = NSMutableString.alloc()
fdescription = ""
fdate = NSMutableString.alloc()
fdate = ""
fcontent = NSMutableString.alloc()
fcontent = ""
}
}
func loadRssRefresh(data: NSURL) {
let myParser : XmlParserManager = XmlParserManager.alloc().initWithURL(data) as! XmlParserManager
myFeed = myParser.feeds
tableView.reloadData()
self.refresher.endRefreshing()
}
Upvotes: 2
Views: 2053
Reputation: 26927
.alloc() is unavailable in Swift: Use object initializers instead
This error message is pretty descriptive. It means that you shouldn't use alloc
in Swift.
You could initialise your string that way:
let str = NSMutableString()
But you can also use a Swift string:
var str = ""
Upvotes: 2
Reputation: 11555
Just use
elements = NSMutableDictionary()
ftitle = NSMutableString()
Upvotes: 3