1

I am trying to implement the following method in swift:

From the class FLIROneSDKImageReceiverDelegate, which is subclassed inside my ViewController class as so:

class ViewController: UIViewController, FLIROneSDKImageReceiverDelegate,
    FLIROneSDKStreamManagerDelegate,
                        FLIROneSDKImageEditorDelegate{

Note that I have already created a bridging header etc.

In the FLIROneSDKImageReceiverDelegate header file:

- (void) FLIROneSDKDelegateManager:(FLIROneSDKDelegateManager *)delegateManager didReceiveBlendedMSXRGBA8888Image:(NSData *)msxImage imageSize:(CGSize)size;

Am I wrong in thinking that this is the correct way to implement this function?

func FLIROneSDKDelegateManagerdidReceiveBlendedMSXRGBA8888ImageimageSize(delegateManager: FLIROneSDKDelegateManager!, msxImage: NSData, size: CGSize){

Note that FLIROneSDKDelegateManager is a class.

Laxsnor
  • 857
  • 1
  • 12
  • 21

2 Answers2

1

Off the top of my head, but try this:

func FLIROneSDKDelegateManager(delegateManager: FLIROneSDKDelegateManager!, didReceiveBlendedMSXRGBA8888Image msxImage: NSData!, imageSize size: CGSize) {

    // method imp

}
Aaron Wojnowski
  • 6,352
  • 5
  • 29
  • 46
  • 1
    This fails because FLIROneSDKDelegateManager is both a class and the name of the function and it's using the class in the function parameters. – Laxsnor May 09 '16 at 22:14
  • This answer looks correct to me. What error message do you get. – Paulw11 May 09 '16 at 22:21
  • Huh that's interesting. It seems to complain that the `FLIROneSDKDelegateManager` class isn't found when I actually try to compile it. Changing `delegateManager` to `id` in Objective-C and `AnyObject` in Swift seems to get it to compile and conform to the protocol. Would that maybe be a workaround @Laxsnor ? – Aaron Wojnowski May 09 '16 at 22:23
  • I switched the swift to this: `func FLIROneSDKDelegateManager(delegateManager: AnyObject!, didReceiveBlendedMSXRGBA8888Image msxImage: NSData!, imageSize size: CGSize) { ` - is that what you had in mind? It doesn't compile now complaining that it conflicts with the objective c header. – Laxsnor May 09 '16 at 22:26
  • @Laxsnor Iff you can alter the Objective-C protocol header those two should work nicely together (nothing should be impacted by it). If you don't have write access to the protocol then obviously this isn't an option though. – Aaron Wojnowski May 09 '16 at 22:29
  • 1
    I was able to get it to work by modifying the Objective C header to `- (void) FLIROneSDKDelegateManager:(NSObject *)delegateManager didReceiveBlendedMSXRGBA8888Image:(NSData *)msxImage imageSize:(CGSize)size;` and the swift to: `func FLIROneSDKDelegateManager(delegateManager: NSObject!, didReceiveBlendedMSXRGBA8888Image msxImage: NSData!, imageSize size: CGSize) {` – Laxsnor May 09 '16 at 22:31
  • 2
    The problem seems to be related to FLIR people ignoring convention that functions should start with a lower case letter, since their company name is all caps. This causes a conflict between the class and the function, but I am not sure if this is acceptable or if it is a bug in Swift. It may be worth reporting to Apple. Changing the function signature to `flirOneSDKDelegateManager...` avoids the issue. – Paulw11 May 09 '16 at 22:40
0

@Laxsnor's solution in the comments on the answer by @aaron-wojnowski helped me too, thanks both.

To consolidate:

The problem is a conflict created by the name FLIROneSDKDelegateManager being used as a both a class name and a function name - which seems to be OK in Objective-C but not in Swift.

Replacing the class FLIROneSDKDelegateManager with NSObject in the function parameter seems to solve the problem without side-effects. This has to be done in both the Objective-C protocol header file and the Swift delegate class source file.

NOTE I also found this same solution applied more broadly to Swift-ify the entire FLIROneSDK at https://github.com/jruhym/flirmebaby.

Happy developing for FLIROne on Swift. (I'm new to FLIROne and relatively new to Swift so apologies if my language isn't quite precise enough.)

Simon Pickup
  • 832
  • 12
  • 19