Spencer Bigum
Spencer Bigum

Reputation: 1931

How to initialize a Class and use Extensions in swift

I have a custom class that uses UIView or NSObject etc.. and I override the init, however I want to be able to pass a custom parameter to this class when it initializes, but I can't figure out how to do that. Any ideas?

class SettingLauncher: NSObject, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
    override init(controller: UIViewController){
        // cant pass this as a param, causes error
        super.init()
    }
}

What I want to be able to do is

let settingsLauncher = SettingLauncher(controller: self)

Upvotes: 0

Views: 61

Answers (1)

Ahmed Eid
Ahmed Eid

Reputation: 4804

I think the error you're encountering is due to the use of override which is used only if you are overriding a method that has the same signature

class SettingLauncher: NSObject, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
    init(controller: UIViewController){
       // init super class accordingly  
       // super.init() 
    }
}

Upvotes: 2

Related Questions