On 08/09/2015 23:06, Charles Srstka wrote:
On Sep 8, 2015, at 4:43 PM, has <hengist.p...@virgin.net <mailto:hengist.p...@virgin.net>> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to