I have a codebase with many hundreds of ObjC #defines for settings in an iOS App. e.g.
#define kSettingName NO
However, these are seemingly not visible to Swift code (not in scope error) as I'm adding new Swift code to the codebase that still needs to access all of these settings (as does the old ObjC code). Is there a good way to have these many settings visible in Swift?
So far, the best way I've come up with is find/replacing YES/NO with true/false (which makes them visible to Swift, but then, you can't easily do:
if kSettingName { }
in Swift. I could write an Int32 extension:
extension Int32 {
var isTrue: Bool { return self != 0 }
static func == (lhs: Int32, rhs: Bool) -> Bool {
if rhs {
return lhs != 0
} else {
return lhs == 0
}
}
}
Which leads to being able to use either
if kSettingName.isTrue { }
or
if kSettingName == true { }
but both are a little less nice than just
if kSettingName { }
Does anyone have any better ideas here?