Obj-C interop: Prevent bridging from Foundation classes?

I have an Obj-C category on NSLocale implementing these readonly properties:

@property (class, nonatomic, nonnull, readonly) NSLocale *searchLocale;
@property (nonatomic, nonnull, readonly) NSString *extendedLanguageCode;

Now when I wanna access it from Swift, I've to write (NSLocale.search as NSLocale).extendedLanguageCode . Is there a way to avoid the casting to NSLocale?

I'm aware I could write a Swift extension like this:

extension Locale {
	var extendedLanguageCode: String {
		(self as NSLocale).extendedLanguageCode

However, that doesn't scale well. I have multiple properties and I'd need such glue code for all of them.

So I was looking for a switch to tell the compiler that for a specific class property it should not apply the bridging from NSLocale to Locale and actually return an NSLocale in Swift.

Any idea how to solve this?

Terms of Service

Privacy Policy

Cookie Policy