Member-only story
Any or AnyObject in Swift
Any and AnyObject. Not the same.
4 min readJan 30, 2020
Sometimes you want to work with types that are not necessarily the standard set of literals given to us by Swift.
Difficulty: Beginner | Easy | Normal | Challenging
Prerequisites:
- Be able to produce a “Hello, World!” iOS application (guide HERE)
- Protocols in Swift (guide HERE) would be useful, as would knowledge of Equality (guide HERE)
- String Interpolation is used later in this article (guide HERE)
Terminology
Any: An instance of any type, including function types
AnyObject: an instance of any class type
Concrete: A type that can be instantiated
Instance: An example or single occurrence of something
Method: a group of statements that together can perform a function
NSNumber: Objective-C type for storing numbers
NSString: Objective-C type for storing Strings
Properties: fields of classes
Protocol: A blueprint on methods, properties and requirements to suit a piece of functionality