different import statement in objective c - objective-c

I was trying to debug a problem we were having in our React-Native on SDK
In our existing code, I see they have done
#import "CleverTap.h"
#import "CleverTapReactManager.h"
and docs says to do
#import <CleverTapSDK/CleverTap.h>
#import <CleverTapReact/CleverTapReactManager.h>
What is the difference between both the imports in swift? or they are the same?

#import "" first check the header in project folder then goes to system library, and the #import<> checks for system headers.
Read: https://swift007blog.wordpress.com/2017/01/13/include-vs-import/

Related

Importing a Swift class of a framework in Objective-C (test) code

I'm trying to import a Swift class from my framework MyFramework in my unit test code:
In my Objective-C test file, I do:
#import MyFramework;
This line causes a compilation error:
Include of non-modular header inside framework module 'MyFramework': 'src/core-ios/MyFramework/Classes/MyFramework-Bridging-Header.h'
inside the "MyFramework-Swift.h" file. In that file, I can see a plain import from
#import "src/core-ios/MyFramework/Classes/MyFramework-Bridging-Header.h"
I'm not sure what to do. My framework "defines" modular headers, but it sound like the problem is that bridging header file which is included with its entire path rather than just doing #import <MyFramework/MyFramework-Bridging-Header.h>.
Any help appreciated!
While calling swift class in objective c
In Bridging-Header add #import "myClass.h". This is objective c class
where you are using swift class.
In myClass.m add #import < yourProjectName_swift.h >
In myClass.h or myClass.m add "#swiftcalss;"
first or second point may cause to your error.

Bridging header doesn't work with two frameworks (Flurry)

I have a bridging header in my project (named "Antoine Bellanger-Bridging-Header.h" if this helps) and then when I import my first framework
#import "SWRevealViewController.h"
everything works.
But when I import the second one
#import "Flurry.h"
I have two errors :
Flurry.h file not found
Swift Compiler Error : Failed to import bridging header "/Path"
I would like to know if the compiler error could be caused by the first error ?
Thanks in advance for your help.
EDIT : I have tried this with another project and I have the same error. May it come from the Flurry files ?
#BC_Dilum : Flurry.h is a file that I want to import and from the documentation of the site, it should be included like that. See https://developer.yahoo.com/flurry/docs/analytics/gettingstarted/ios/
Okay I found the solution. I just made a mistake and #BC_Dilum was right by adding
#import "Flurry/Flurry.h"
and not just #import Flurry.h

Using #import ... as default instead of #import <...>

When creating a new Objective-C class, XCode inserts this line into the .h file:
#import <Foundation/Foundation.h>
Instead, I want it to be the following automatic:
#import Foundation;
Where can I set it?
Xcode inserts the imports because this is how it is defined in the "new file templates". Instead of changing those built-in templates you should clone them and make your own, with adjusted import statement.
Look at this answer how to do that: https://stackoverflow.com/a/33743/396578

xCode 4.4 does not get all the .pch file headers imports?

This is my .pch file -
//
// Prefix header for all source files of the 'English Club' target in the 'English Club' project
//
#import <Availability.h>
#ifndef __IPHONE_4_0
#warning "This project uses features only available in iOS SDK 4.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "Helper.h"
#import "Animations.h"
#import "Constants.h"
#import "SoundPlayer.h"
#import "UAirship.h"
#import "UAStoreFront.h"
#import "UIIMagesNames.h"
#import "UIView+Sizes.h"
#import "HelpButton.h"
#import "SoundPlayer.h"
#import <RestKit/RestKit.h>
#import "UIHelpSoundFiles.h"
#endif
Still it is very frequent that Xcode will give me errors that he can not find those classes. (Helper for example).
The thing is that the project will be compiled and work fine but I have hundreds of errors that disturb me looking for the real ones.
Any idea why?
This appears to be a known issue in Xcode 4.4 (as seen in the release notes)
It is suggested to Delete the PCH index folder to workaround this issue.
To locate this folder, in Xcode, open the Organizer and select the Projects tab, then select the project in the left-hand pane. You should see the Derived Data path for this particular project with a small arrow to Show in Finder. If you click on this arrow, you will be taken to the right location in Finder. If you then navigate to the Index subfolder and delete PrecompiledHeaders folder, you should be all set.
Xcode should re-index, and re-create this folder, but the errors should be gone.
I found that just updating your pch file (add and delete space) and rebuild will cause xcode to fix those problems
I know this is an old post but I wanted to share my experience.
Im running Xcode 6.1 the fix was to delete the Tests target. for example MyProjectNameTests.
Also check if both your app.pch and the app_Test.pch have the required imports. Sometimes you might be staring at the main pch, but the errors are for the unit tests pch.
Xcode 5 Update:
You can now delete derived data straight from Xcode Organizer. Delete, clean, and build solved the problem for me.
Also one of the problem could be that .pch file is not set for a target. To do that do the following:
1. Go to the target settings.
2. Option Precompile Prefix Header set to YES.
3. For Prefix Header add a project relative path or an absolute path.

What is #ifdef __OBJC__ doing and why libraries listed below?

I believe the #ifdef __OBJC__ directive is ensuring that I import the following class libraries for Objective-C only. What is the purpose of listing the class libraries after the ifdef statement? Doesn't this code example kinda defeat the purpose?
#ifdef __OBJC__
#import <foundation/foundation.h>
#import <uikit/uikit.h>
#import <coredata/coredata.h>
#endif
</coredata/coredata.h></uikit/uikit.h></foundation/foundation.h>
Objective-C is a superset of C (just like C++ is) and fairly often files from the different languages will be used in the same project and share headers, especially the prefix header. The #ifdef __OBJC__, like #ifdef __cplusplus, lets you include (or #import for Objective-C) headers for only the appropriate language.
The same header included in .c, .cpp, and .m files (with default compiler settings) would only have __OBJ__ defined for the .m files.
Basically in that code if you are using Objective C it will import those 3 libraries
#import <foundation/foundation.h>
#import <uikit/uikit.h>
#import <coredata/coredata.h>
The purpose of that if, is to not import them unless it is necessary.
They are listed after the #endif just as a reminder, so it makes the code easier to read. Otherwise you'd have to look up above to see what the #endif was ending.
The reason this is done is so that this code can still be compatible with regular C code that may want to use the functionality in that C file (at least that's what it looks like to me). By including those libraries only when OBJC is defined it ensures that the libraries are ONLY imported when you are compiling for objective c and not for standard C.