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

Tony Parker anthony.parker at apple.com
Tue Jul 19 10:57:28 CDT 2016


Please don’t resort to that; I’d rather fix the bug. =)

- Tony

> On Jul 19, 2016, at 8:53 AM, Brent Royal-Gordon <brent at architechies.com> wrote:
> 
>> 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