Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Design Pattern. Why did they include Any, AnyObject

I've recently moved to Swift from regular objc. And yes, I know how to use Any and AnyObject.

But I'm curious why Apple decided on AnyObject and Any. Why is it good? What problem is it solving? How much developer time is it saving?

like image 412
shle2821 Avatar asked Mar 17 '23 20:03

shle2821


1 Answers

For backward compatibility with existing Cocoa libraries. Classes like NSDictionary, NSArray, etc. do not enforce type on all objects contained. Also in Obj-C there's id which is a pointer to any Obj-C object.

like image 158
Diego Allen Avatar answered Apr 02 '23 18:04

Diego Allen