This is what I did:
In Swift class created the enum
enum Origin {
case Search(searchTerm: String, searchResultsPageNum: Int)
case Discovery(pageNum: Int)
}
Then in my Class, created enum property and functions (that are visible to Objective C) to set and get values of the enum property.
@objc class GameSession: NSObject
{
...
var gameOrigin: Origin?
...
let originStr = "origin"
let notSpecified = "Not Specified"
@objc func getOrigin() -> NSDictionary
{
guard let origin = gameOrigin else {
return [originStr: notSpecified]
}
switch origin {
case .Search(let searchTerm, let searchResultsPageNum):
return ["searchTerm": searchTerm, "searchResultsPageNum": "\(searchResultsPageNum)"]
case .Discovery(let pageNum)
return ["pageNum": pageNum]
default:
return [originStr: notSpecified]
}
}
@objc func setSearchOriginWith(searchTerm: String, searchResultsPageNum: Int, filtered:Bool)
{
self.gameOrigin = Origin.Search(searchTerm: searchTerm, searchResultsPageNum: searchResultsPageNum, filtered: filtered)
}
@objc func setDiscoveryOriginWith(pageNum: Int)
{
self.gameOrigin = Origin.Discovery(pageNum: pageNum)
}
}
I'm afraid it's not possible, Apple has a list of Swift Type Compatibility which explicitly excludes enumerations defined in Swift without Int
raw value type.
Reference