Re: Swift generics, circular type declarations, and segfaults, oh my!
Re: Swift generics, circular type declarations, and segfaults, oh my!
- Subject: Re: Swift generics, circular type declarations, and segfaults, oh my!
- From: has <email@hidden>
- Date: Tue, 08 Sep 2015 23:45:31 +0100
On 08/09/2015 23:06, Charles Srstka wrote:
On Sep 8, 2015, at 4:43 PM, has <email@hidden
<mailto:email@hidden>> wrote:
Yeah, the goal is for each app-specific glue to subclass the concrete
library classes (which provide the query-building and AE dispatch
services using raw four-char codes, and already work nicely in
themselves), then use protocol extensions to add the app-specific
vars/funcs into those. So I don't have a problem with mixing-in the
base functionality as well; just wish swiftc felt the same way as
well. :p
Perhaps you don’t need to provide concrete library classes at all, but
simply ask your app-specific glue to implement your protocols instead
of subclassing anything?
Quite possibly, if I can get all the standard functionality to fit
nicely into protocol extensions, I don't have a problem with the library
just providing the general building blocks and the glue code generator
creating the actual classes. Oh, and I've just figured why Swift was
complaining that the MyObject 'glue' class didn't implement BaseProtocol
- it's because its error messages are kinda crappy, and what it actually
meant was that MyObject needs to implement the Init protocol too (since
the typealias in the BaseProtocol uses Init as a constraint).
Et voila, code that compiles and runs, seemingly without cratering,
since typealiases in protocols appear to be rather less intolerant of
circular referencing than generic classes:
// library
protocol Init {
init()
}
protocol BaseProtocol {
typealias ObjectType: Init
typealias ElementsType: Init
func newObject() -> ObjectType
func newElements() -> ElementsType
}
extension BaseProtocol {
func newObject() -> ObjectType { return ObjectType() }
func newElements() -> ElementsType { return ElementsType() }
}
// glue
class MyObject: BaseProtocol, Init {
typealias ObjectType = MyObject
typealias ElementsType = MyElements
required init() {}
}
class MyElements: MyObject {
}
// test
let obj = MyObject()
print(obj.newObject()) // MyObject
print(obj.newElements()) // MyElements
I will need to spend some more time building it out and testing it, but
(touch-wood) it looks like the problem might be cracked at last. Wahey!
Many, many thanks (you've no idea how nuts this has been driving me),
and fingers crossed I'll have a nice shiny new Apple event bridge to
sell y'all shortly. :)
has
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Swift generics, circular type declarations, and segfaults, oh my! (From: has <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: Fritz Anderson <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: has <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: Quincey Morris <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: has <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: Quincey Morris <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: Charles Srstka <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: has <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: Quincey Morris <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: Charles Srstka <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: has <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: Charles Srstka <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: has <email@hidden>) |
| >Re: Swift generics, circular type declarations, and segfaults, oh my! (From: Charles Srstka <email@hidden>) |
- Prev by Date:
Re: Swift generics, circular type declarations, and segfaults, oh my!
- Next by Date:
Re: Swift generics, circular type declarations, and segfaults, oh my!
- Previous by thread:
Re: Swift generics, circular type declarations, and segfaults, oh my!
- Next by thread:
Re: Swift generics, circular type declarations, and segfaults, oh my!
- Index(es):