Redefinition of module 'Realm' - ios

I working on an Objective c project, and trying to get it to work with Swift too.
I've allready have been throw this process in the past, but did'nt get this error.
After adding use_framworks to my podfile, and replacing all "" imports with <> or #import, I'm getting this error:
Redefinition of module Realm
In the module.modulemap file:
framework module Realm { //This is the line the error is on
umbrella header "Realm.h"
export *
module * { export * }
explicit module Private {
header "RLMAccessor.h"
header "RLMArray_Private.h"
header "RLMListBase.h"
header "RLMMigration_Private.h"
header "RLMObjectSchema_Private.h"
header "RLMObjectStore.h"
header "RLMObject_Private.h"
header "RLMOptionalBase.h"
header "RLMProperty_Private.h"
header "RLMRealmConfiguration_Private.h"
header "RLMRealm_Private.h"
header "RLMResults_Private.h"
header "RLMSchema_Private.h"
}
explicit module Dynamic {
header "RLMRealm_Dynamic.h"
header "RLMObjectBase_Dynamic.h"
}
}
Any help?
Thanks

You only need to use the use_frameworks! keyword in CocoaPods if you're bringing in a dependency that uses Swift code. Is that what you're doing?
If you're also starting to access Realm code from a Swift class, make sure you've included the Swift/RLMSupport.swift bridging header as well.
Aside from that, looking at the CocoaPods issue where this sort of issue was reported, you should also make sure that you've absolutely removed all traces of #import "" everywhere.
If that still doesn't work for you, then you might need to add some more information to your question about how your project is set up with regards to how it uses both Objective-C and Swift, and what your podfile looks like.

Related

Import Obj-C file which imports auto-generated Swift header

This is a partial duplicate of Import a file in bridging-header which imports Swift header but I encounter the same issue as Rich
But what about enums declared in Swift? :(
I am porting an Obj-C iPad app to the iPhone. However I am a Swift developer who would really rather not rewrite existing functionality; replacing the UI instead.
I created a new target for the iPhone version. In my bridging header I import an obj-c class that uses #import "ProjectName-Swift.h". Since this file is autogenerated it doesn't exist when I build this new target. The linked answer is to add a #class but the legacy code makes use of an enum which is now giving the error "Expected a type".
// File that I am currently importing
-(void)setSmileyType:(SmileyFace)type andDelegate:(id<NumberRatingDelegate>)delegate;
// This line now throws an error "Expected a type"
//File that was previously auto imported
#objc public enum SmileyFace: Int {
#objc enum in Swift is exposed as a C-enum in ProjectName-Swift.h .
(Using a macro SWIFT_ENUM.)
You can put something like this into your Objective-C header files which are using the Swift enum:
typedef enum SmileyFace: NSInteger SmileyFace;
(Same as the first part of the generated code with the macro SWIFT_ENUM.)

How to add integrate code from Github into your existing project

I want to get the device location in the application that I want to develop. I have created a SWIFT project and I want to add the code here
https://github.com/intuit/LocationManager
into my existing swift project.
So here it says
Manually from GitHub
Download all the files in the INTULocationManager subdirectory.
Add the source files to your Xcode project (drag and drop is easiest).
Import the INTULocationManager.h to your bridging header.
Swift: Add #import "INTULocationManager.h" to your bridging header.
So basically can I just drag the source code to my project?
Also how do I create the bridging header?
then let say how do I use it in my ViewController?
Thanks
Maybe you should consider using CocoaPods as it may be easier for you to integrate, and in the long-run, is easier to update.
To answer your specific question about a manual installation:
Yes, you can just drag the source code into your project. Instructions for creating the bridging header can be found on the internet (for example, here).
Next, as the instructions say, add #import "INTULocationManager.h" to your bridging header, e.g:
#ifndef TestBridgingHeader_Bridging_Header_h
#define TestBridgingHeader_Bridging_Header_h
#import "INTULocationManager.h"
#endif /* TestBridgingHeader_Bridging_Header_h */
To use the library, you have to translate the example given on the Github page from Objective-C to Swift.
let locMgr = INTULocationManager.sharedInstance()
locMgr.requestLocationWithDesiredAccuracy(INTULocationAccuracy.City, timeout: 10, block: { currentLocation, achievedAccuracy, status in
if status == .Success {
} else if status == .TimedOut {
} else {
}
})
This is made easier by remembering a few rules:
Method calls in Obj-C are called via enclosing square brackets (e.g. [INTULocationManager sharedInstance]) while in Swift they use dot-syntax (e.g. INTULocationManager.sharedInstance())
Enums such as INTULocationAccuracyCity generally get translated to only their last part (.City in this case). Swift infers that .City is equivalent to INTULocationAccuracy.City.
Obj-C blocks such as INTULocationRequestBlock are equivalent to Swift closures of the same type.

Use of undeclared type 'RoboViewController' Swift

I install RoboReaderPDF framework via pod in my project and I imported it in my Bridging-Header.h file
the issue is when I am trying to instantiate the RoboViewController I am getting this error
Use of undeclared type 'RoboViewController'
any help!?
Looks like your bridging header has not been set up correctly. It should have the following structure.
#ifndef Bridging_Header_h
#define Bridging_Header_h
#import <RoboReaderPDF/RoboReader.h>
#endif
Importing the RoboReader.h file will also import the view controller (check file contents).
Additionally, also check that your bridging header has been specified under Objective-C Bridging Header key in Swift Compiler - Code Generation segment in Build settings.

How to import swift file into objective-c file in a swift project

The situation is a little complicated. I have a Swift project, and I have imported some Objective-C files into this project. Now, I want to use some Swift classes in these Objective-C files. How to do that?
It seems this reference covers everything:
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
Specifically:
Importing Swift into Objective-C
When you import Swift code into Objective-C, you rely on an
Xcode-generated header file to expose those files to Objective-C. This
automatically generated file is an Objective-C header that declares
the Swift interfaces in your target. It can be thought of as an
umbrella header for your Swift code. The name of this header is your
product module name followed by adding "-Swift.h". (You’ll learn more
about the product module name later, in Naming Your Product Module.)
Example:
Foo.swift in product named ExampleProduct
#objc public class Bar: NSObject {
var x: Int = 3
}
Blah.m in same product:
#import <Foundation/Foundation.h>
#import <ExampleProduct-Swift.h>
void doStuff() {
Bar *y = [[Bar alloc] init];
printf("%ld\n", (long)y.x);
}
It's even easy to call doStuff() from a Swift file if you create an Objective-C header file that defines the function prototype and then import that header file in the bridging header.
There's no limit to jumping back and forth.
Based on the comments it looks like you're having trouble importing the reverse bridging header.
Try this in terminal to ensure you're naming the file correctly:
% cd ~/Library/Developer/Xcode; find . -name '*-Swift.h'
I get (scroll all the way to the right):
./DerivedData/ExampleProduct-avoxifngmebkkqgndldocildsfcm/Build/Intermediates/ExampleProduct.build/Debug-iphonesimulator/ExampleProduct.build/DerivedSources/ExampleProduct-Swift.h
./DerivedData/ExampleProduct-avoxifngmebkkqgndldocildsfcm/Build/Intermediates/ExampleProduct.build/Debug-iphonesimulator/ExampleProduct.build/Objects-normal/x86_64/ExampleProduct-Swift.h
./DerivedData/ExampleProduct-avoxifngmebkkqgndldocildsfcm/Build/Intermediates/ExampleProduct.build/Debug-iphonesimulator/ExampleProductTests.build/DerivedSources/ExampleProductTests-Swift.h
./DerivedData/ExampleProduct-avoxifngmebkkqgndldocildsfcm/Build/Intermediates/ExampleProduct.build/Debug-iphonesimulator/ExampleProductTests.build/Objects-normal/x86_64/ExampleProductTests-Swift.h
Also, potentially a dup of:
How to call Objective-C code from Swift
With 326 upvotes that's worth studying!

Bridging Header Issues

I'm trying to add a Swift file to my app and get a "Failed to import bridging header" error, among others.
Bridging-Header code:
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "Menu.h"
In build settings, try setting "Embedded Content contains Swift Code" to Yes.
Also, it looks like its failing to recognize objects from UIKit, so try adding "import UIKit" atop one of your Swift files.

Resources