Home > other >  How to overcome Class name clashing in Swift
How to overcome Class name clashing in Swift

Time:09-17

Given this code

import UIKit

class Configuration{
    static var name = "test"
}

class MyButton: UIButton{
    func test(){
        let name = Configuration.name // Type 'UIButton.Configuration' has no member 'name'
    }
}

Is there a way to reference the Configuration class from inside the MyButton class instead of the (new to iOS 15) nested struct Configuration

Of cause just renaming the Configuration class here would be an easy fix, but I'm curious as to if there is another way to handle this.

CodePudding user response:

Your app target is a module, which has a name. (Look in the app target build settings to find out what it is.) Use that to namespace the class:

let name = MyApp.Configuration.name...

CodePudding user response:

Ok. As it turns out the first thing i tried, which was putting my target name as a prefix the the class name was working, for some reason XC needed to have its caches cleared before acknowledging it.

  • Related