0

i want to write a Cocoa Touch Framework in Swift and want to use it in different projects. As far as everything works fine.

Now I would like to extend my framework with constants which I can use outside of the framework. My problem is that i can't use the constant from the Swift-Framework in my Objective-C project.

For example: MyFramework.swift

 public struct Constants{
     public static let constant = "myConstant"
 }

and

public class MyClass : NSObject {

    public func myFunc(){
     doSomeThing
    }
}

In a Swift-Project i can access everything (MyClass and Constants). So this i what i want to do in Swift and Objective-C:

import MyFramework

class ClassWithImport{
 var xC = Constant.constant
}

But how can i make this in Objective-C?? At the moment i've in my MyFramework.h:

#import "MyFramework-Swift.h"

and this in the Class where I want to use the constants for example. After the import you can see i get access to MyClass, but i can't access the struct Constans.

#import <MyFramework.framework/Headers/MyFramework.h>

@implementation ClassWitheImport

- (void)funcOC
{
  MyClass *test;
  test.myFunc;
}
@end

Do I have to do that with the constants in a different way? The idea to make it this way, I came after I saw this link: Global constants file in Swift

Community
  • 1
  • 1
Paixsn
  • 1,256
  • 3
  • 12
  • 22

1 Answers1

1

The real problem is the use of the struct. The struct is a swift only feature and isn't compatible to Objective-C.

A workaround can be found in the post of rintaro.

Next to the link to his post I would like you also, just as he, provide the direct link to Apple documentation concerning the subject.

Community
  • 1
  • 1
Paixsn
  • 1,256
  • 3
  • 12
  • 22