0

I am trying to access a swift class from an Objective-C file. I have done all the generic things needed to access the swift file from Objective-C such as #import "target-Swift.h" so I can access Swift methods through a shared instance. So the issue is not hooking up Swift with Objective-C. My question is specifically the syntax to access the Swift class on its own.

The swift class is in a Utilities.swift file and it currently looks like:

@objc public class Metadata : NSObject {
    var pum: String = ""
    var pmm: String = ""
    var id: NSInteger = 0
}

I am trying to use it in an objective-C method with

Metadata * m = [Metadata new];

The class itself compiles but when I try to call it as above, compiler is giving error: 'Use of Undeclared identifier 'Metadata'

What is the correct syntax to gain access to this class?

user1904273
  • 4,562
  • 11
  • 45
  • 96
  • Did you check (all of) https://stackoverflow.com/questions/24002369/how-to-call-objective-c-code-from-swift? – Martin R Feb 25 '19 at 14:19
  • You may need to add this top of the .m file `#import ` – Shehata Gamal Feb 25 '19 at 14:19
  • 1
    I got it to work by adding @class Metadata; in .h file. I guess I should delete question unless people thing this is useful information. AtClass (can't repeat at sign in this comment) believe it or not is not mentioned in the question you reference Martin which seems to have more on calling objc from swift rather than swift from objc – user1904273 Feb 25 '19 at 14:33

0 Answers0