When programming in Swift, what are the advantages and disadvantages of using a structure to store all of your constants?
Normally I would go for a class, but fast classes do not yet support properties of the stored type. I would like to write my code in the form of Sample A, and not in Example B, purely because of readability, fewer lines of code, and one operator does what is read (read constant that cannot be rewritten).
// Sample A.swift struct Constant { static let PI = 3.14 } //Sample B.swift private let globalPI = 3.14 class Constant { class var PI: Float { return globalPI } }
If I just refer to Constant.PI in terms of Struct (for use in computing, printing, conditional expressions, etc.), am I wasting with the copies that are produced? Are there any copies if I just refer to a constant as Constant.PI in other parts of my code?
source share