[swift-users] Possible swift 3 method rewrite issue with NSRequestConcreteImplementation ?

Brent Royal-Gordon brent at architechies.com
Tue Jul 19 10:53:48 CDT 2016


> On Jul 19, 2016, at 8:20 AM, John Spurlock <john.spurlock at gmail.com> wrote:
> 
> Is there anything I can do in the meantime as a swift-only workaround to fix my custom NSCoder?

Horrible possibility: `class_addMethod()` *is* available from Swift. You might be able to do some old-fashioned runtime hackery like:

	class MyCoder: NSCoder {
		@objc func __encodeInt(_ intv: Int, forKey: String) { ... }
		
		override class func initialize() {
			super.initialize()
			
			// XXX I think this needs to be guarded against being run more than once.
			let donor = class_getInstanceMethod(self, #selector(__encodeInt(_:forKey:)))
			class_addMethod(self, Selector("encodeInt:forKey:"), method_getImplementation(donor), method_getTypeEncoding(donor))
		}
		
		...
	}

-- 
Brent Royal-Gordon
Architechies



More information about the swift-users mailing list