Define struct that is treated like a class in Swift -


in swift string structure treated class object when using nscoder encodeobject(_:forkey:) method. know string directly bridged objective-c class, nsstring, there way make custom struct behaves similarly? perhaps bridge custom class? want able this:

struct sortedarray <value: comparable> {}  // need create bridge between  // sortedarray , nssortedarray? can that? class nssortedarray <value: comparable> : nsobject, nscoding {     required init?(coder adecoder: nscoder) {}     func encodewithcoder(acoder: nscoder) {} }  class myclass : nsobject, nscoding {     private var objects: sortedarray<string> = sortedarray<string>()     required init?(coder adecoder: nscoder) {         guard let objects = adecoder.decodeobjectforkey("objects") as? sortedarray<string> else { return nil }         self.objects = objects     }     func encodewithcoder(acoder: nscoder) {         acoder.encodeobject(objects, forkey: "objects")     } } 

this isn't possible. se-0058 address it, deferred out of swift 3. final implementation of se-0058 hoped handle more objc bridging; example allowing c++ or .net bridging in more generic solution.


Comments