Reputation: 137
I have a view controller with objective c class , now i want to open the view controller that contain class swift. I have tried several times but it is not opening th swift class how can i open the swift class from objective c class.
Upvotes: 1
Views: 3890
Reputation: 878
I initially faced same trouble but after searching on web I got success. you should follow exact same as I have mentioned below:
Step by step Swift integration for Xcode Objc-based project:
Create new *.swift
file (in Xcode) or add it by using Finder
Create an Objective-C bridging header when Xcode ask you about that
Implement your Swift class with @objc
attribute:
import UIKit
@objc public class CustomView: UIView {
override func draw(_ rect: CGRect) {
// Drawing code
}
}
Open Build Settings and check those parameters:
Defines Module : YES
Product Module Name : myproject
Make sure that your Product Module Name doesn't contain any special characters
Once you've added *.swift file to the project this property will appear in Build Settings
This header is auto-generated by Xcode
Import Swift interface header in your *.m file
#import "myproject-Swift.h"
Don't pay attention to errors and warnings. Clean and rebuild your Xcode project. Done!
Upvotes: 7