swift - Crash casting WKNSURLRequest as? other type -


i'm getting hard crash when try cast wknsurlrequest (and other classes, webkit framework).

e.g. in playground:

import uikit import webkit  final class sigh: nsobject { }  nsclassfromstring("nsobject") as? sigh.type  nsclassfromstring("wknsurlrequest") as? sigh.type 

the cast nsobject works (i.e. returns nil), cast wknsurlrequest crashes exc_bad_access - have assumed return nil well.

anyone got ideas might causing this?

wknsurlrequest not inherit nsobject

@interface wknsurlrequest : wkobject <nscopying> 

and wkobject root class:

ns_root_class @interface wkobject <wkobject> 

unlike java, classes must inerhit object, obj-c not require classes inherit nsobject.

the swift<->obj-c bridge has explicit support nsobject , subclasses, i'm not sure can handle other root objects equally well. on export side (swift classes being exposed obj-c) it's not possible make own root class. swift class shall exposed obj-c must inherit nsobject, i'd bridge has not been designed arbitrary root classes in mind.

of course, none of explains crash, simple bug in swift compiler or swift runtime. don't reference classes statically name, happens @ runtime , swift runtime may assume whatever nsclassfromstring returns subclass of nsobject , when tries interact class, fail @ runtime because assumption plain wrong. in case still bug imho explain why there crash.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -