WKNSURLRequest casting crash how? another type

I get a hard crash when I try to use WKNSURLRequest (and other classes, all from the WebKit environment).

eg. on the playground:

import UIKit
import WebKit

final class Sigh: NSObject { }

NSClassFromString("NSObject") as? Sigh.Type

NSClassFromString("WKNSURLRequest") as? Sigh.Type

A throw is made from NSObject (i.e. returns nil), but is discarded from WKNSURLRequest with EXC_BAD_ACCESS - I would assume that it will return as well nil.

Anyone have any ideas what might cause this?

+4
source share
1 answer

WKNSURLRequest not inherited from NSObject

@interface WKNSURLRequest : WKObject <NSCopying>

And WKObjectis the root class:

NS_ROOT_CLASS
@interface WKObject <WKObject>

Unlike Java, where all classes must inerhit from Object, Obj-C does not require all classes to inherit from NSObject.

Swift โ†” Obj-C NSObject , , , , . ( Swift Obj-C) . , Obj-C, NSObject, , - .

, , โ€‹โ€‹ Swift Swift. , , , Swift , , NSClassFromString, NSObject, , , . IMHO, , .

+3

Source: https://habr.com/ru/post/1673419/


All Articles