I am having coding design difficulties with Array in Swift, see this post. So I decided to turn to the old NSMutableArray.
I'd like to know if there are any known problems of this approach. Any pitfalls and known practices?
It's an agony working with array/dictionary in Swift!
NSMutableArray does not support generics so I have to stick to Swift builtin array.
I finally have to employ a not-so-perfect-and-ugly workaround:
/// Act as a reference container for value types.
open class ValueBox<ValueType> {
public var value: ValueType
public init(_ value: ValueType) {
self.value = value
}
}
// Arrays in a dictionary
typealias TranslationUnitBox = ValueBox<[TranslationUnit]>
var translations = [String: TranslationUnitBox>()
// Later in some other code
if let box = translations["en"] {
box.value[index].translatedText = "..."
}