Reputation: 13020
There are lots of question about how to use swift code in objective c
. I had swift based project. there is Objectice C file where i need to use swift code.
Xcode did not create ProjectName-Swift.h
automatically. So i created manually and check the following things.
Generated interface header name : ProjectName-Swift.h
Product Module Name : myproject
Defines Module : YES
Embedded Content Contains Swift : YES
Install Objective-C Compatibility Header : YES
Add @objc
in swift class
import UIKit import SwiftyJSON
@objc class User: NSObject, NSCoding { }
Then Import ProjectName-Swift.h
in objective c file. But gives error Unknown Type name User
I had tried with add @class User
It gives error forward reference using @class
How can I fix this erros
Upvotes: 1
Views: 837
Reputation: 4891
Hopefully you have already solved the problem after reading the documentation referenced by @AnupamMishra, but just in case: try removing from the project the ProjectName-Swift.h
file that you created manually. It hides the file of the same name auto-generated by Xcode and not listed in your project. The file is still there, somewhere deep in the DerivedData directory.
Another observation: you didn't have to set Objective-c Generated Interface Header Name
in Build Settings
. Xcode would generate one and name it myproject-Swift.h
by default, since myproject
is your Product Module Name
.
Upvotes: 1