我已經創建了我作爲constants.swift應用恆定的文件,我使用的是結構如下Swift常量文件?
struct moments {
struct parameter {
static let email = "email"
static let me = "me"
static let fields = "fields"
static let params = "id, name, first_name, last_name, picture.type(large), email"
}
struct title {
static let timeLineTitle = "Moments"
static let settingsTitle = "Settings"
static let menuTitle = "Menu"
static let openCamera = "Say Cheese!!! "
static let openGallery = "Pick from Moments "
static let addAudio = "Record Audio "
static let addNote = "Write Note "
}
struct notification {
static let notificationIdentifier = "NotificationIdentifier"
}
struct entity{
static let image = "Image"
static let note = "Note"
static let Audio = "Audio"
}
struct menu {
static let home = "Home"
static let settings = "Settings"
static let logout = "Logout"
}
struct cell {
static let cellIdentifier = "timeLineCell"
static let imageCell = "imageCell"
}
}
來定義常量,但我發現多個其他選項像使用class,singleton和enum我想知道哪些是在我的應用程序中使用常量的有效方式...
爲了某些合乎邏輯的目的,例如爲了常量而對常量進行分組時,爲常量創建單獨的文件是有意義的。因爲它們代表相同協議中的字符串。創建常量只是爲了讓所有常量位於一個地方,使得代碼的可讀性低於在使用這些常量的文件中定義常量。 – dasblinkenlight
如果常量與現有類型相關,最好創建一個擴展並在其中添加常量 – Adolfo
@Adolfo您可以向我提供一個示例,瞭解如何做到這一點 –