question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extending • Swift-class component returns nil

See original GitHub issue

Extending with custom components doesn’t work for Swift classes. There is an issue in JasonComponentFactory in method build:withJSON:withOptions::

NSClassFromString(componentClassName) returns nil for Swift classes, because Swift class name have a different format: <appName>.<className> or <appName>_<targetName>.<className> instead of just <className> in Obj-C classes.

Therefore component class names must have a prefix for Swift classes, i.e. MyAppName.JasonSuperComponent

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RomanSlyepkocommented, Jul 4, 2019

yes, @objc(MySwiftClass) works fine

1reaction
clsourcecommented, Jul 3, 2019

Try this in your swift code

https://stackoverflow.com/a/30895110

All swift classes use the Product Module Name a dot and the classname for their namespace (Module.Class). If you wanted to use “MySwiftClass” name for the class within your Objective-C code; you can add @objc(MySwiftClass) annotation to expose the same swift class name (without the module):

@objc(MySwiftClass)
class MySwiftClass{
    ...
}

Then

Class myClass = NSClassFromString(@"MySwiftClass");

Will contain the class instead of being nil.

Read more comments on GitHub >

github_iconTop Results From Across the Web

New stored property always returns nil | iOS Swift
A new stored property created for exisiting class using extension. While getting value its always returning nil value. The below code is what...
Read more >
Extensions — The Swift Programming Language (Swift 5.7)
Extensions¶. Extensions add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend types for ...
Read more >
Extending optionals in Swift | Swift by Sundell
Converting nil into errors. When working with optional values, it's very common to want to convert a nil value into a proper Swift...
Read more >
Understanding Functional Components vs. Class ... - Twilio
A class component is a JavaScript class that extends React.Component which has a render method. A bit confusing?
Read more >
4. Object Types - iOS 8 Programming Fundamentals with Swift ...
Inside a static/class method, self is the type. ... But if nil was returned, any attempt on the caller's part to access members...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found