Search code examples
iosswiftsubclassingswift-extensions

Subclass an existing Swift Singleton


I am adding functionality to an AWS class that creates a singleton (AWSIdentityManager) and the code for that class is in flux (AWS are improving it). I would like to make my added functionality more distinct from the AWS code so that I don't have to keep changing it when they upgrade.

Can I achieve this by subclassing or extension?

My goal is not to create another copy of the existing singleton, I just want to add methods (and hopefully properties) to it, without making too many changes in the released code.

I should note the following: The original class is written in Obj-C. I would like to have properties if possible.


Solution

  • To extend

    extension AWSclass {
    func functionA () { ...}
    
    }
    

    usage

    AWSclass.shared.functionA()