-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can we use swift instead of objective Objective-C ? #221
Comments
Contribution would be much welcome. This would likely have to be an option in both CLI and the library API, which would be subject to review. |
Hi, I managed to use swift like this:
Let me know if you have any questions. Edit. This is my podspec file:
|
Thanks @mateioprea! I guess I should pick up on Swift programming - someday:) |
@mateioprea Greetings, I have created my Swift file which looks like this: `import UIKit class File: UIViewController, ARSCNViewDelegate, ARSessionDelegate {
} Also as of now, we have .h and .m file how will we expose this swift class to React native.(You have mentioned in your comments but it is not very clear from it). Thanks in advance. |
@kashifaliquazi if you're talking about the react native module created using create-react-native-module, try something like this: Add the following lines to your swift file: @objc(File)
class File: NSObject {
@objc
override static func requiresMainQueueSetup() -> Bool {
return false
}
@objc func testFn() {
print("This is a test function")
}
} In the .m file in your project add the following lines: #import "React/RCTBridgeModule.h"
@interface RCT_EXTERN_MODULE(File, NSObject)
RCT_EXTERN_METHOD(testFn)
@end In the React Native project use: import React, {Component} from 'react';
import {NativeModules} from 'react-native';
let {File} = NativeModules;
export default class TestComponent extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
File.testFn();
}
} you should see "This is a test function" logged in either Xcode or React Native console. |
@mateioprea Thank you so much for the response. We are able to call Swift code from React Native, But we are not able to change ViewControler for the Swift Class. Here is How AppDelegate looks like in actual iOS: `#import "AppDelegate.h" #import <React/RCTBridge.h> @implementation AppDelegate
@end` When We try to replicate this Code to out react-native-librery(One we created) build fails at self.window.rootViewController = vc; // This Gives error. As I am understanding we are not able to reference uiControler than we have in actual acess to We are able to make it work when created Bridge in iOS folder of main React app and adding
This code in AppDelegate.m file. Can you tell us what getting wrong here or maybe any other way to go to AR Mode(using AR Kit) from our created React-Native library . Any help would be much appriciated. Thanks, Thanks, |
@kashifaliquazi why don't you use https://viromedia.com/viroar ? Its MIT licensed. |
Support is now in progress, see #353. I hope to finish it in the next 2-4 weeks or so. |
Hi guys, I made the exact same steps posted here to have swift files working on the lib, but when i execute the example project i get this error: (On iphone 11 simulator)
Then i tried to run on the device (iphone X) and i got the same error but for arm64. HELP! |
Hello !
First, thanks for this project, it's very nice !
I would like to use swift language instead of Objective-C, is it possible to generate a swift example ?
thanks a lot
The text was updated successfully, but these errors were encountered: