1

I'm already using Swift and since the update of Xcode beta4 to beta5 there are two compiler errors in the following code.

1st: init function - Error: "Overriding declaration requires an 'override' keyword" --> Solved

2nd: class FeedTableCell : UITableViewCell - Error: "Class 'FeedTableCell' does not implement its superclass's required members"

I couldn't find the required members in the documentation and other research - does anyone know what to do?

Code:

    import UIKit

    class FeedTableCell : UITableViewCell{

@IBOutlet var userLabel: UILabel!
@IBOutlet var hoopLabel: UILabel!
@IBOutlet var postLabel: UILabel!

func loadItem(#user: String, hoop: String, post: String) {
    userLabel.text = user
    hoopLabel.text = "#"+hoop
    postLabel.text = post
}

init(style: UITableViewCellStyle, reuseIdentifier: String!) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
}

override func awakeFromNib() {
    super.awakeFromNib()
}

override func setSelected(selected: Bool, animated: Bool){
    super.setSelected(selected, animated: animated)
}

}

Joe
  • 207
  • 1
  • 2
  • 9
  • If you don't use init, awakeFromNib and setSelected, simply remove it, it should help. – Greg Aug 06 '14 at 14:53
  • possible duplicate of [UIView initializer swift Xcode 6 beta 5](http://stackoverflow.com/questions/25160942/uiview-initializer-swift-xcode-6-beta-5) – Martin R Aug 06 '14 at 14:55

1 Answers1

8

I resolved this issue by adding required init(coder aDecoder: NSCoder!) method:

class FeedTableCell : UITableViewCell{

    @IBOutlet var userLabel: UILabel!
    @IBOutlet var hoopLabel: UILabel!
    @IBOutlet var postLabel: UILabel!

    func loadItem(#user: String, hoop: String, post: String) {
        userLabel.text = user
        hoopLabel.text = "#"+hoop
        postLabel.text = post
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }

    required init(coder aDecoder: NSCoder!) {
        super.init(coder: aDecoder)
    }


    override func awakeFromNib() {
        super.awakeFromNib()
    }

    override func setSelected(selected: Bool, animated: Bool){
        super.setSelected(selected, animated: animated)
    }
}

The other solution is remove init method at all:

class FeedTableCell : UITableViewCell{

    @IBOutlet var userLabel: UILabel!
    @IBOutlet var hoopLabel: UILabel!
    @IBOutlet var postLabel: UILabel!

    func loadItem(#user: String, hoop: String, post: String) {
        userLabel.text = user
        hoopLabel.text = "#"+hoop
        postLabel.text = post
    }

    override func awakeFromNib() {
        super.awakeFromNib()
    }

    override func setSelected(selected: Bool, animated: Bool){
        super.setSelected(selected, animated: animated)
    }
}
Greg
  • 25,317
  • 6
  • 53
  • 62