3

I just started to add Swift in my ObjC framework project because it is quite new, solver directly the gap to CloudKit and therefore maybe interesting to migrate to code step-by-step to Swift.

I tought i start with something simple, a protocol.

I did the following: - I created a Swift file, and as you know there is no bridghing header for frameworks - added my protocol in this file

and know i like to use it in my class's but well how? The solution for classes is simple, you just define a forward declaration. But was is about protocols?

It seems at them moment this is the last element which i have to migrate or do you know a approach?

Updated:

What i forget to mentioned, i marked the protocol @objc, because in general it is possible to use a Swift protocol in ObjC but i just see at the moment restrictions in frameworks

1
  • In your Obj-C implementation (.m) file did you add #import <##Your-Project-Name##>-Swift.h? Commented Jun 8, 2014 at 17:25

1 Answer 1

1

Here's an example in my project name SwiftProtocol:

Renderable.swift

@objc protocol Renderable
{
    @objc func render()
}

Triangle.h

#import "SwiftProtocol-Swift.h"    // This is very important!

@interface Triangle : NSObject <Renderable>

@end

Triangle.m

@implementation Triangle

- (void)render
{
   // Do some rendering
}

@end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.