Convert Swift to Objective-C

This question already has an answer here:

  • Is it possible to use Swift’s Enum in Obj-C? 5 answers

I’d like to know how to convert the Swift enum just below to Objective-C:

enum MeatTemperature: Int {
    case Rare = 0, MediumRare, Medium, WellDone

    var stringValue: String {
        let temperatures = ["Rare", "Medium Rare", "Medium", "Well Done"]
        return temperatures[self.rawValue]
    }

    var timeModifier: Double {
        let modifier = [0.5, 0.75, 1.0, 1.5]
        return modifier[self.rawValue]
    }
}

Simply prefix the enum with @objc

@objc enum MeatTemperature: Int {
    case Rare = 0, MediumRare, Medium, WellDone

    var stringValue: String {
        let temperatures = ["Rare", "Medium Rare", "Medium", "Well Done"]
        return temperatures[self.rawValue]
    }

    var timeModifier: Double {
        let modifier = [0.5, 0.75, 1.0, 1.5]
        return modifier[self.rawValue]
    }
}

Check this – https://developer.apple.com/swift/blog/?id=22

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » Convert Swift to Objective-C

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录