UIGestureRecognizer setState: in swift 3 [duplicate] - swift

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.

Related

No such module purelayout in swift with manual installation?

I have been at this for over an hour. I am desperate.
I am trying to implement this here https://github.com/enisgayretli/EGFloatingTextField and this is my previous question Best way to achieve UILabel animation effect in Swift?
For the text field to work I need to import Purelayout. I'm working in swift and this is where things don't work- I've tried all the methods on the purelayout github but can't for the life of me import purelayout.
No matter what I do I get no such module purelayout. I am trying to do the manual installation and I have 1. Dragged and copied the purelayout source files into my project 2. Written the import Purelayout.h line in my bridging header
Where am I going wrong here? Am I configuring my header wrong? When I drag the files in it wants to configure a new Bridger and creates a blank file.. Could this be the problem?
My project will not compile. I can't understand this.

use swift file into Objective-C project

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"

Why my import MessageUI in AppDelegate is not visible within my UITableViewController?

Since Swift files are visible for each others, why my import within Appelegate is not visible for one of my controllers? I get an error there.
This is called Access level for Swift Modules. Default access level for Swift modules is internal, that is to that file itself.
Have a look here in Apple documentation Access level in Swift module
You need to import frameworks/modules in which ever class you are using.
Put import MessageUI at the top of the file where you declare your PBOUserViewController class (which I hope is contained in a separate .swift file than your AppDelegate).

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>

Why is Foundation.h not imported in the standard Xcode templates?

I just noticed that when I create iPhone application using standard templates in Xcode (View Based Application, Window based application etc) the header files only import UIKit.h (and not Foundation.h). So if the Foundation.h file is not imported, how can one use Foundation classes like NSString, NSArray etc in the program ? Shouldn't it be throwing an error?
It is imported in the precompiled header file (extension .pch) in your project.
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
As to why UIKit.h appears to have two import lines per file since it also shows up above, though, I'm not too sure. It shouldn't matter anyway, as the second #import line won't cause UIKit to be included again if it's already included in the precompiled header file.
If you take a look at some of the individual UIKit headers, they import Foundation themselves. As BoltClock noted, it's also in the standard .pch
The reason that it can be put in all these places is mentioned in "The Objective-C Programming Language":
This directive is identical to #include, except that it makes sure that the same file is never included more than once. It’s therefore preferred and is used in place of #include in code examples throughout Objective-C–based documentation.
You want to make sure that every file that needs access to the symbols defined in Foundation has them. The reason it's repeated is that it helps with reading and understanding the code; it says "This code relies on the stuff that's in this header".
It looks like the template files are designed to work with or without precompiled headers, so they import the header files they use. If you create a subclass of NSObject the template file will import Foundation. If you create a subclass of a UIKit object the UIKit header will be imported.
OK, so why can you use Foundation classes like NSString when only UIKit is imported. Well nearly all of the UIKit headers import Foundation.h!
Hope this make sense.