What is the difference between NSObject and AnyObject? When to use two?

I am trying to create an array to hold strings or an array of a custom class. Am I better off creating a dictionary?

+6
source share
1 answer

AnyObject is a Swift representation of type Objective-C id . It is more general than NSObject (i.e., every NSObject is AnyObject , but not every AnyObject is NSObject ).

On the other hand, the question depends on how you are going to use the structure. Using a more specific class for the general structure (Swift-typed array or dictionary) will allow you to take advantage of strong typing, while using a more universal type will allow you to be more dynamic. Actually, it depends on what you are going to use for the class.

+6
source

All Articles