Using SDK in a Swift project

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

Peter Steffey

  • Posts: 2
  • Joined: Tue Oct 18, 2016 1:08 am

Using SDK in a Swift project

PostTue Oct 18, 2016 1:15 am

I am trying to create a macOS Swift-based app using your SDK, but am having trouble importing the needed files into Swift to use. I created my bridging header like normal, but my AppDelegate.swift file throughs a "Use of undeclared type 'IBMDSwitcher....'" error when I try to use any of the classes in BMDSwitcherAPI.h.

To clarify, a few questions:
1) What does "#import <list>" do? I can't find any documentation for it online. Does it have anything to do with the different versions provided in the SDK?
2) Are the only files I need to import the BMDSwitcherAPI.h and BMDSwitcherAPIDispatch.cpp, or do I need other files as well? I only ask because Swift is struggling to understand the use of "class" in BMDSwitcher.h, as I believe it is looking for @interface and @implementation, which is more common for objective-c.
3) In general, has anyone had any luck getting this working in Swift? I can't even run the sample projects because Xcode 8.0 can't compile the code, and I don't know enough old-style objective-c to fix it.

Thank you in advance for any help you can provide.
Offline

Waqqas Sharif

Blackmagic Design

  • Posts: 21
  • Joined: Tue Oct 04, 2016 1:47 am

Re: Using SDK in a Swift project

PostThu Oct 20, 2016 10:45 pm

It should be possible to use the DeckLink API as it is possible to use any other C++ based library in Swift.

I found the following reference which may help with your integration [1].

Based on a comment in that document "You cannot import C++ code directly into Swift. Instead, create an Objective-C or C wrapper for C++ code." it is my understanding that you will likely need to develop an Objective-C wrapper around the DeckLink API, and then use this wrapper via a bridging header in Swift.

The usage of the DeckLink API in your wrapper will be the same as with any other DeckLink API based application. To this end, I recommend reviewing SDK manual chapters "2.4.1 Capture", & "2.4.2 Playback" for a high-level overview of the steps required to perform a capture or playback operation.

1) What does "#import <list>" do? I can't find any documentation for it online. Does it have anything to do with the different versions provided in the SDK?

The #import directive was added to Objective-C as an improved version of #include. Whether or not it's improved, however, is still a matter of debate. #import ensures that a file is only ever included once so that you never have a problem with recursive includes. However, most decent header files protect themselves against this anyway, so it's not really that much of a benefit.


2) Are the only files I need to import the BMDSwitcherAPI.h and BMDSwitcherAPIDispatch.cpp, or do I need other files as well? I only ask because Swift is struggling to understand the use of "class" in BMDSwitcher.h, as I believe it is looking for @interface and @implementation, which is more common for objective-c.

Usually importing DeckLinkAPI.h is enough but depends on which part of the API you are looking to use.


3) In general, has anyone had any luck getting this working in Swift? I can't even run the sample projects because Xcode 8.0 can't compile the code, and I don't know enough old-style objective-c to fix it.

Technically it is possible but not sure whether some one have done this.


[1] https://developer.apple.com/library/ios ... TP40014216
Offline

Marcemoyano

  • Posts: 5
  • Joined: Fri Sep 30, 2022 12:57 am
  • Real Name: Marcelo Moyano

Re: Using SDK in a Swift project

PostFri Nov 18, 2022 2:10 pm

Hello, is this setup currently working for M1 Macs ? Please let me know. Thank you.
Offline

Dominik Lenk

  • Posts: 17
  • Joined: Tue Apr 18, 2017 9:52 am

Re: Using SDK in a Swift project

PostWed Jun 14, 2023 4:54 pm

Has anyone gotten this to work and is willing to share their Objective-C wrapper and maybe an example or two?

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 22 guests