2

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()


}

2 Answers 2

3

Just use

elements = NSMutableDictionary()
ftitle = NSMutableString()
Sign up to request clarification or add additional context in comments.

Comments

2

.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 = ""

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.