Complexity Analysis of Structs and Enums

时间:2015-04-25 16:53:31

标签: swift data-structures struct enums

Does anyone know the complexity to initialize a struct or enum?

Or, do you know which of the 3 costs the least amount of time/resources to allocate memory for?

In my situation, I'm simply using a struct/enum to house variables for me to reference later. As an example, here's the equivalent struct/enum:

Using a struct:

struct Identifier {
    static let key = "a long string as a dictionary key, shortened using struct."
}
let dictionaryItem = aDictionary[Identifier.key]

Now using enums:

enum Identifier: String {
    case Key = "a long string as a dictionary key, shortened using enum."
}

let dictionaryItem = aDictionary[Identifier.Key.rawValue]

Which would be faster? Which is more effi

0 个答案:

没有答案