This is a question I asked yesterday, and copy-pasted my question details and answer I get on StackOverflow topic just to have it here.
I read inline documentation of Swift and I am bit confused.
Anyis a protocol that all types implicitly conform.
AnyObjectis a protocol to which all classes implicitly conform.
Here is a sample code:
What I don’t understand is why
Why compiler doesn’t say anything? Those types are declared as structs.
MyStruct cannot be passed to the method on the top because it does
not conform to AnyObject.
Could you help me understand why it(…)?
vacawama from SO answered:
Because you have Foundation imported, Int, Double, and Float get converted to NSNumber when passed to a function taking an AnyObject. This is done to make life easier when calling Cocoa and Cocoa Touch based interfaces. If you remove import UIKit (or import Cocoa for OS X), you will see:
error: argument type Int does not conform to expected type 'AnyObject'when you call