I'm trying to create an array to store Strings or an array of custom class. Am I better off creating a dictionary?
AnyObject
is Swift's representation of Objective-C's id
type. It's more general than NSObject
(i.e. every NSObject
is an AnyObject
, but not every AnyObject
is a NSObject
).
On the other part of the question - depends on how you intend to use the structure. Using a more particular class for the generic structure (Swift's typed array or dictionary) will allow you to enjoy the benefits of the strong typing, whereas using a more generic type will allow you to be more dynamic. Really it depends on what you intend to use the class for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With