So what is the counterpart to AnyClass aka. AnyObject.Type for AnyValue? There is no and I don’t see any good name for it.
More confusion with generalized existentials: Any<class> vs. AnyClass aka AnyObject.Type Any<class> makes it crystal clear that you’re using an instance of a class not an instance of .Type. It should be consistent. I’m not proposing for AnyStruct or AnyEnum here, it would be enough to get AnyValue in Swift, but I did considered both in my proposal. Lets say we also would have something like One<A, B> which picks A or B and we have generalized struct and enum. That said we could create AnyValue like this typealias AnyValue = One<struct, enum>. Again this is not the main part of the proposal. -- Adrian Zubarev Sent with Airmail Am 9. Juni 2016 um 13:09:28, Patrick Smith ([email protected]) schrieb: 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 <[email protected]> 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 Rename AnyObject and remove current AnyClass Proposal: SE-NNNN Author(s): Adrian Zubarev Status: Awaiting review 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 Motivation In Swift 3 the standard library will correspond to a particular guideline. 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. 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 -@objc public protocol AnyObject {} +@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 [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
