[swift-evolution] [Pitch] Rename `AnyObject` to `AnyClass` and drop current `AnyClass`

Patrick Smith pgwsmith at gmail.com
Thu Jun 9 06:09:19 CDT 2016


I find this more confusing, not less. AnyClass suggests that will be any class, but it’s not, it’s any class instance. So I think it’s less accurate.

For arguments that AnyStruct and AnyEnum will come, I don’t agree with those either. AnyValue would make more sense to me. The fact that a value’s type is a struct or enum is irrelevant, just as AnyObject makes no promise about the superclass. I don’t believe there would be much or anything you could do knowing if something was a struct or enum anyway — both support properties and methods, mutations, yet cases can only be used with a concrete enum type. So AFAIK, there would no um value in having both AnyStruct and AnyEnum.

So I am happy staying with AnyObject, as it describes what the actual instance is. And if AnyValue comes, they would pair nicely together.

Patrick


> On 9 Jun 2016, at 8:08 PM, Adrian Zubarev via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I added a draft proposal here: https://github.com/DevAndArtist/swift-evolution/blob/rename_anyobject_remove_anyclass/proposals/nnnn-rename-anyobject-remove-anyclass.md <https://github.com/DevAndArtist/swift-evolution/blob/rename_anyobject_remove_anyclass/proposals/nnnn-rename-anyobject-remove-anyclass.md>
> Rename AnyObject and remove current AnyClass
> 
> Proposal: SE-NNNN <https://github.com/apple/swift-evolution/blob/master/proposals/nnnn-rename-anyobject-remove-anyclass.md>
> Author(s): Adrian Zubarev <https://github.com/DevAndArtist>
> Status: Awaiting review <x-msg://100/#rationale>
> Review manager: TBD
> Introduction
> 
> From the beginning AnyObject protocol and AnyClass type-alias felt wrong and confusing. This proposal aims to sort out the confusion and provide a consistency for future version of Swift.
> 
> Swift-evolution thread: [Pitch] Rename AnyObject to AnyClass and drop current AnyClass <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160516/018283.html>
> Motivation
> 
> In Swift 3 the standard library will correspond to a particular guideline <https://github.com/apple/swift-evolution/blob/master/proposals/0006-apply-api-guidelines-to-the-standard-library.md>. This means that the Type suffix will be removed almost everywhere. This provides good readability and makes usage of .Type more clearer and consistent. Furthermore this change is a first step towards consistency for generalized existentials <https://github.com/austinzheng/swift-evolution/blob/az-existentials/proposals/XXXX-enhanced-existentials.md>.
> 
> Short example:
> 
> -func construct(type: AnyClass) -> AnyObject?
> +func construct(type: AnyClass.Type) -> AnyClass? {
>     if let objectType = type as? NSObject.Type {
>         return objectType.init()
>     } else {
>         return nil
>     }
> }
> Proposed solution
> 
> Remove current AnyClass type-alias from the standard library and rename current AnyObject protocol to AnyClass. Then migrate existing code from AnyClass to AnyClass.Type and from AnyObject to AnyClass.
> 
> // Remove completely
> -public typealias AnyClass = AnyObject.Type
> 
> // Rename to AnyClass
> - at objc public protocol AnyObject {}
> + at objc public protocol AnyClass {}
> Impact on existing code
> 
> This change will break existing code, and will require a migrator to translate Swift 2 code into Swift 3 code.
> 
> Alternatives considered & Future consistency
> 
> Use generalized existentials with any-class requirement Any<class> instead, which won’t make it into Swift 3 in time:
> AnyClass equals Any<class> or typealias AnyClass = Any<class>
> AnyClass.Type equals Any<class>.Type
> Add AnyValue type-alias with generalized existentials and value keyword:
> AnyValue equals Any<value> or typealias AnyValue = Any<value>
> AnyValue.Type equals Any<value>.Type
> Or instead AnyValue add AnyStruct and AnyEnum type-aliases:
> AnyStruct equals Any<struct> or typealias AnyStruct = Any<struct>
> AnyEnum equals Any<enum> or typealias AnyEnum = Any<enum>
> AnyStruct.Type equals Any<struct>.Type
> AnyEnum.Type equals Any<enum>.Type
> Example:
> 
> // Accept any type that conforms to `SomeProtocol`
> func doSomething(with interface: SomeProtocol) { ... }
> 
> // Accept any class that conforms to `SomeProtocol`
> // We use shorthand syntax for existentials here (SE-0095)
> func doSomething(with interfaceReference: AnyClass & SomeProtocol) { ... }
> func doSomething(with interfaceReference: Any<class> & SomeProtocol) { ... }
> 
> // Accept any value that conforms to `SomeProtocol`
> // Missing counterpart to `AnyClass`
> func doSomething(with interfaceValue: AnyValue & SomeProtocol) { ... }
> func doSomething(with interfaceValue: Any<value> & SomeProtocol) { ... }
> 
> // Or more specific value types:
> func doSomething(with interfaceValue: AnyStruct & SomeProtocol) { ... }
> func doSomething(with interfaceValue: Any<struct> & SomeProtocol) { ... }
> 
> func doSomething(with interfaceValue: AnyEnum & SomeProtocol) { ... }
> func doSomething(with interfaceValue: Any<enum> & SomeProtocol) { ... }
> 
> 
> 
> -- 
> Adrian Zubarev
> Sent with Airmail
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160609/33b84c70/attachment.html>


More information about the swift-evolution mailing list