toupper/Wyler

Wyler framework import in objective-c ViewController

valnenov opened this issue · 1 comments

I downloaded, compiled and tested successfully your Wyler project (framework and sampleapp) and now I am trying to import the framework in my objective-c ViewController.

I followed your instructions and did all the usual tricks of calling Swift from objc but ran into a number of problems. The last one, on which I got stuck, is trying to call the startRecording from in my ViewController. Can you please tell me what is the correct syntax to do that?

This is what I did:
Added: #import "Wyler/Wyler-Swift.h" in my ViewController.m
Added: @Class ScreenRecorder; in ViewController.h
Wyler-Swift.h was generated automatically by Xcode
Declared: ScreenRecorder * screenRecorder; in my ViewController.m
Tried invoking the method startRecording but cannot figure out the correct syntax even after I looked in Wyler-Swift.h

screenRecorder.startRecording(saveToCameraRoll: cameraRollSwitch.isOn, errorHandler: { error in
debugPrint("Error when recording (error)")
})

Get an error: Property 'startRecording' not found on object of type 'ScreenRecorder *'
Seems like it might have something to do with this method being declared as a class instead of an instance method in the Wyler.framework .. and this is where I am stuck:-(

Also what is the Objective-c syntax for stop recording?

Hi @valnenov ,
thanks for opening the issue. Basically, to expose the methods to the Objective-C runtime we have to explicitly mark them with the @objc attribute, otherwise they won't be visible. For more info, please check https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c

I adapted them and committed in a separate branch, https://github.com/toupper/Wyler/tree/feature/ObjCSupport , to avoid cluttering master with that. In there, I created a very simple Objective C sample app with the sole purpose of showing how it compiles calling start and stop recording.

ScreenRecorder *screenRecorder = [ScreenRecorder init];
  [screenRecorder startRecordingTo:[NSURL init] size:CGSizeMake(0, 0) saveToCameraRoll:true errorHandler:^(NSError* error){
  }];
  [screenRecorder stoprecordingWithErrorHandler:^(NSError* error){
  }]; 

Please note that since we are importing a framework we have to do it as:
#import <Wyler/Wyler-Swift.h>

Let me know if you need more help.