use swift file into Objective-C project - swift

Can anyone tell me how can I use swift file into my objective-C project?
I have a swift file which inherits from UIViewController instead of NSObject. I am trying to use the swift file but I am not able to figure out how.
When I add my swift file into objective-C project, it usually asks to create a bridging header.
In that header file I am importing my swift file as -
#import "SlideController.swift"
and my bridging file name is objcToSwift-Bridging-Header.h
I read many answers which asks to import file
#import "MyProductModuleName-Swift.h"
into the .m file, but I can't find any such file in my project.
I also changed the defines module = YES as shown in another answer.
But still I am not able to access swift file.
What am I missing? Please tell me the right steps to figure it out.

After you created Bridging header.
Go to Build Setting =>Search for "Objective-C Bridging Header"
Just below you will find ""Objective-C Generated Interface Header Name" file
and import That file in your view controller.
ex.In my case: "Dauble-Swift.h"

Related

Cannot find interface declaration in myproject-swift.h after converting Obj-C to Swift

My project is in a Pod.
And I want to swiftify a CollectionViewCell (TVPromotionCollectionViewCell).
I just change the codes to Swift and added #import "MyProject-Swift.h" in the file which has the collectionview using TVPromotionCollectionViewCell.
But the 'MyProject-Swift.h' cannot find the BaseCollectionViewCell which is written by obj-C and I've not edited.
I read the solution of
Cannot find interface declaration in myproject-swift.h
But... I can not used the solution in my project.

UIGestureRecognizer setState: in swift 3 [duplicate]

You can't write to self.state in the subclass unless you import UIGestureRecognizerSubclass.h as indicated here.
In a Swift environment, I'm confused how I'd go about importing this. I tried import UIGestureRecognizerSubclass.h, and without the .h, but I still can't write to self.state.
How would I accomplish this?
The Swift equivalent is simply:
import UIKit.UIGestureRecognizerSubclass
That imports the appropriate header.
You need to have or create a -Bridging-Header.h file to import objc headers such as the one you want. The import line looks like this:
#import <UIKit/UIGestureRecognizerSubclass.h>
If you don't already have a bridge header file in your app, the easiest way to get one is to add an objc class to your project, and xcode will ask if you want one, then creates the file and ties it into the settings for you. You can then delete the objc class.
Everything in that header file is automatically made available to your Swift code, no need to add any import lines in your swift files.

File not found when trying to import a header file into the bridging header?

I'm trying to import my speech recognition framework into my project. Sadly my project is in Swift and speech rec is in objc. I don't see a problem with this. I have created a bridging header file before importing the framework and compiled to make sure it has no errors. Then I dragged the framework into my project. Got a successful compile again. Now I type this in my header file:
#ifndef Bridging_Header_h
#define Bridging_Header_h
#import "SpeechKit/SpeechKit.h"
#endif
And then I get the error: "SpeechKit/SpeechKit.h" file not found
I have tried reimporting the framework. Deleting and making a new header file etc. Nothing seems to work. I don't get why it's not picking up the header files from the framework.
Does anyone have any ideas? All help would be greatly appreciated.
Thank you so much.
Try #import "SpeechKit.h" or #import <SpeechKit/SpeechKit.h> instead #import "SpeechKit/SpeechKit.h"
use #import <SpeechKit/SpeechKit.h> in bridging header and don't forget to place import SpeechKit in your swift file

Trying to use the STHorizontalPicker Library from GitHub but getting multiple errors

I'm trying to use the open source STHorizontalPicker library to implement a horizontal picker to my project but when importing the .m and .h files from GitHub to my project I'm getting multiple errors when compiling.
Does it require any special implementation?
I'm simply copying the .h and .m and adding to the project. Error are like : property 'cornerRatius' cannot be found in forward class object 'CALayer'...
Do I have to import some class to those files ?
Thnaks in advice.
Do I have to import some class to those files?
Yes, you'll need Quartz.
#import <QuartzCore/QuartzCore.h>

iPhone SDK : How to localize a Class?

I am trying to localize a class (.h & .m files) in my application. I made the same operation as when I localized my interface (xib -> Get info -> make file localizable). I created a second .h and a second .m file, and I made the modifications I needed for the new location. Great !
But it just doesn't work...
I get the error:
duplicate symbol _OBJC_METACLASS_
Does anyone have a clue ? Thanks a lot !
you are just on the wrong path..
For localization you need not create separate .m & .h files.Only Xibs are to be created.
Other than that you have to create separate Localizable.strings file for each localization.
For more understanding just chk out this link http://www.switchonthecode.com/tutorials/a-simple-localization-example-for-the-iphone
It contains the link for downloading the sample code also.