gpt4 book ai didi

iOS:如何在 Swift 中使用 Objective-C 中的#define?

转载 作者:行者123 更新时间:2023-11-30 12:08:38 25 4
gpt4 key购买 nike

我在 Objective-C 中使用包含 #define 的 Constants.h 文件,并且我想在 Swift 3.0 中使用它。你觉得可能吗?

我有不同的类型,例如:

/*int*/        #define EVENT_ID         12
/*Class name*/ #define FORM_TO_USE RegistrationForm_xxxx_xxx
/*String*/ #define name @"name1"

有什么想法吗?

最佳答案

Swift 常量的最佳实践 -

Constants.swift

struct Constants {
static let someValue = "TEST"
static let arrayOfTests: [String] = ["foo", "bar", someValue]
}

struct Event {
static let id = 12
static let name = "event Name"
}
struct NotificationKey {
static let welcome = "event Name"
}

用途:

let eventID  = Event.id
let eventName = Event.name
let aValue = Constants.someValue
let notification = NotificationKey.welcome

关于iOS:如何在 Swift 中使用 Objective-C 中的#define?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46361789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com