0

I've got the following swift autogen model, that i can't change

@objcMembers public class Device: NSObject, Codable { 

public enum Auth: String, Codable {
        case enabled = "ENABLED"
        case supported = "SUPPORTED"
        case notSupported = "NOT_SUPPORTED"
        case bypassed = "BYPASSED"
    }

public var auth: Auth
public var brand: String

}

I'm trying to access the enum property in my Objective-C class like this self.isAuthEnabled = ([Device.auth.rawValue isEqualToString:@"ENABLED"]);

but I keep getting this error, Property 'auth' not found on object of type 'Device' even though I have access to the brand property, I can't access the enum

  • Only enums with integer raw values are exposed to Objective C. Perhaps [this](https://stackoverflow.com/a/38490781/5133585) still works? – Sweeper Jan 29 '23 at 09:09
  • That may work but I can't change the Device class – mduduzi mthethwa Jan 29 '23 at 09:13
  • 2
    Oh sorry I missed that part of the question. I think you are kind of stuck then. You need to write a Swift wrapper of the enum that can be exposed to ObjC. – Sweeper Jan 29 '23 at 09:16
  • Objective C enums just don’t support this. You’ll want to make a wrapper API that you expose in place of the enum – Alexander Jan 29 '23 at 14:18
  • https://developer.apple.com/documentation/swift/grouping-related-objective-c-constants – Cy-4AH Jan 30 '23 at 09:17
  • You need declare that enum as `struct Auth: RawRepresentable, Equatable, Hashable` – Cy-4AH Jan 30 '23 at 09:18
  • 1
    @Cy-4AH The linked documentation describes how to expose ObjC types to Swift. The OP is looking for a way to do the opposite. – vadian Jan 30 '23 at 10:45

0 Answers0