ios icon indicating copy to clipboard operation
ios copied to clipboard

[BUG] Problem with class names and NIBs

Open PeterStaev opened this issue 4 years ago • 8 comments

I'm using a POD that has Swift code and XIBs for controllers. This is the pod that I'm using:

pod 'iOSPhotoEditor', :git => 'https://github.com/PeterStaev/photo-editor.git', :commit => '5f90ae8f937e1bf4ef3c46d0fda5fef715c7a5de'

When running with JSC (iOS runtime 6.5.2) When I do:

console.log(PhotoEditorViewController);

I get

function iOSPhotoEditor.PhotoEditorViewController() {
[native code]
}

Which is correct and name so when I try to load the controller with the NIB it works. Here is the code that creates the view controller with the NIB:

const bundle = NSBundle.bundleForClass(PhotoEditorViewController.class());
const viewController = PhotoEditorViewController.alloc().initWithNibNameBundle("PhotoEditorViewController", bundle);

With the v8 runtime seems all the classes are renamed. When I try the same log with the new runtime i get:

function _TtC14iOSPhotoEditor25PhotoEditorViewController() { [native code] }

Since the class is renamed the creation of the viewcontroller fails, as the XIB isn't named accordingly. The exact error is:

CONSOLE ERROR: Error: Could not load NIB in bundle: 'NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIKitCore.framework> (loaded)' with name 'PhotoEditorViewController'

PeterStaev avatar Sep 20 '20 19:09 PeterStaev

@PeterStaev I think that's a change in ios 13.4 and above that uses mangled class names

maybe related: https://github.com/NativeScript/ns-v8ios-runtime/commit/2b89d7c83bd8a3414f93974d1a902475c45b21bf same in the JSC runtime: https://github.com/NativeScript/ios-runtime/commit/265c6b675f2f60ed9c639981c6c66576da741028

Since iOS 13.4 object_getClassName and similar functions have started returning the mangled Swift class names instead of the demangled ones that previous versions did.

rigor789 avatar Sep 20 '20 19:09 rigor789

@rigor789 I would agree, but the same code works perfectly fine with JSC. Basically on the demo app, I uninstalled @nativescript/ios and installed tns-ios and the code started working. This is running on a iOS 13.5 sim.

I wouldn't mind the class naming if the XIB could be loaded correctly 😄 Seems JSC somehow correctly registers the class/XIB so it can be loaded, while v8 doesn't.

PeterStaev avatar Sep 20 '20 20:09 PeterStaev

Hmm reading the comment from Darin, seems nested classes are always used with their mangled names.

PeterStaev avatar Sep 20 '20 20:09 PeterStaev

A quick follow up - a workaround seems to be to decorate the view controller with @objc(<CLASS NAME>). This causes the class to not be nested and seems registered correctly.

PeterStaev avatar Sep 20 '20 21:09 PeterStaev

Hi @PeterStaev. i have the same problem, how do you solved?

mvargaslandolfi1993 avatar Sep 23 '21 05:09 mvargaslandolfi1993

Hey @mvargaslandolfi1993, see the comment just above yours :)

PeterStaev avatar Sep 23 '21 06:09 PeterStaev

Yes, I see, but I don't understand where to change it.

mvargaslandolfi1993 avatar Sep 23 '21 23:09 mvargaslandolfi1993

Hi @PeterStaev,

I want to use your photo-editor and having the same problem aas described above. You mentioned a workaround with the view controller with @objc decoration, I really don't know where to change the code. I hope you can help me.

Robernator avatar Apr 22 '22 12:04 Robernator