Using a cocoaPod written in Swift in an Object-C project - ios

I have a problem with the import of an external framework within a Swift class.
My project uses cocoaPod to manage dependencies and is configured as follows:
Main project in OBject-C which uses a pod written in Swift (MyPod).
The Pod Swift (MyPod) must use an external framework (ExternalFramework) written in OBject-C.
There is no way to show ExternlFramewrok inside MyPod. I receive "Use of undeclared type" when I try to use any class of ExternlFramework in MyPod.
I attach the part of the MyPod .podspec:
s.source_files = 'MyPod/Sources/**/*', 'MyPod/LibrariesHeaders/**/*.h'
s.ios.vendored_library = 'MyPod/Libraries/*.a'
s.private_header_files = 'MyPod/MyPod/headers/*.h'
s.ios.vendored_frameworks = 'ExternalFramework.framework'
s.frameworks ='ExternlFramework'
s.prefix_header_contents = <<EOC
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
EOC
Logically I can not modify ExternlFramework in any way but I can change MyPod as desired.
Any suggestions?
Thanks!

Related

Could not build Objective-C module 'mupdfdk'

I'm trying to add mupdf framework to a swift project. I created a new project and copied the mupdfdk.framework to my project and referenced it in the frameworks section. Following is a screenshot of the documentation.
Now my project looks like this.
Then when I try to import it in viewcontroller, I get Could not build Objective-C module 'mupdfdk' error. Are there any other steps I'm missing? Please help.
You need to add this bridging header:
MuPDF-Bridging-Header.h
#ifndef MuPDF_Bridging_Header_h
#define MuPDF_Bridging_Header_h
#import "mupdfdk.framework/Headers/mupdfdk.h"
#endif /* MuPDF_Bridging_Header_h */
and declare it within the Swift Compiler section of the Build Settings:

CocoaPods: Mix Objective-C and Swift

I'm working on a custom CocoaPod to be deployed privately. Most of the code in this pod is existing code written in Objective-C.
All of the Objective-C code is perfectly accessible from both Objective-C and Swift in implementing projects, but I don't seem to be able to access any of the Swift code from either language in the implementing projects. I would like to be able to use and update the existing Objective-C code, but use Swift for anything new and for Swift specific features.
How can I use Swift code from a primarily Objective-C CocoaPod in Swift files in my implementing project?
My CocoaPod is called XibisFrameworkPod, and I've tried using the following import statements in my implementing project Swift files:
import XibisFrameworkPod
import XibisFrameworkPod.Swift
Here's my redacted podspec file:
Pod::Spec.new do |s|
s.name = 'XibisFrameworkPod'
s.version = '0.1.0'
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '7.0'
s.source_files = 'XibisFrameworkPod/Classes/**/*'
end
Turns out I was just missing the public modifier on the class/function declarations:
public class SomeClass : NSObject

Xmppframework could not build module libxml

On DDXMLNode.h
My project import XMPPFramework by cocoapods ,like:
pod 'XMPPFramework', '~> 3.6.6'
I find some way like:
1.header search paths add "$(SDKROOT)/usr/include/libxml2"
2.Other Linker Flags add "-lxml2"
3.Framework Search Path add "/usr/lib/libxml2.dylib"
All not working!
Instead of changing path of the files, you can do what I have done to resolve my error in Xcode 7.2 beta. First check if you have file libxml2.tbd framework and libresolve.tbd framework; if not then add it to you project and replace few things:
#if !(TARGET_IPHONE_SIMULATOR)
//#import dnssd;
#import <dns_sd.h>
#else
//#import dnssdSimu;
#import <dns_sd.h>
#endif
Second thing you have to do is replace this one:
#if !(TARGET_IPHONE_SIMULATOR)
//#import libxml;
#import <libxml/tree.h>
#else
//#import libxmlSimu;
#import <libxml/tree.h>
#endif
This resolved my problem.
Ok, I'll say get down to business. I use Cocoapods at the beginning, everything goes well and do not configure something, but because of the need to modify the source code to meet certain requirements, so manually add XMPPFramework, but encountered all sorts of issues.
The First : Modlue 'libxmlSimu' not found
In order to solve this problem, I did two things:
Download the file https://github.com/robbiehanson/KissXML/blob/master/libxml/module.modulemap
and import to your project. Like this:
Configure Build Settings - Header Search Paths, like this:
The Second : Module 'KissXml' not found
By replace #import KissXml; to #import "DDXML.h"

Cannot configure RestKit with CoreData

I did setup my project to use RestKit and CoreData: added CoreData framework in 'Link binary with libraries' and "pod 'RestKit', '~> 0.24.0'" to my Podfile.
Everything looked fine until I tried to use RKObjectManager's method
managedObjectRequestOperationWithRequest:managedObjectContext:success:failure:
Xcode gives me the following error:
No visible #interface for 'RKObjectManager' declares the selector 'managedObjectRequestOperationWithRequest:managedObjectContext:success:failure:'
There is a #ifdef RKCoreDataIncluded preprocessor directive before this method in RKObjectManager.h, and RKCoreDataIncluded is defined this way:
#ifdef _COREDATADEFINES_H
#if __has_include("RKCoreData.h")
#define RKCoreDataIncluded
#import "RKManagedObjectStore.h"
#import "RKManagedObjectRequestOperation.h"
#endif
#endif
I can't figure out what else do I need to do to enable CoreData in RestKit?
As it turns out in order to use RestKit with CoreData you have to create precompiled header file for your project and add the following line:
#import <CoreData/CoreData.h>
This issue is discussed here: https://github.com/RestKit/RestKit/issues/1564
At compile time, RestKit expects that Core Data has already been imported. Therefore, simply import Core Data before RestKit:
#import <CoreData/CoreData.h>
#import <RestKit/RestKit.h>
There's no need to create a precompiled header, which would create a dependency between the libraries and every single class in your target.

Using RestKit in Swift

I have successfully added 'RestKit' pod into my project and also followed steps described in this article: Cocoapods in swift. I imported the RestKit into my ViewController class's source file:
import RestKit
But I don't know why I can't access it. It doen't show any of the classes in the RestKit. It shows:
'RestKit' No such module exists.
I tried again creating a new project and added 'RestKit'. and created a bridging header and imported 'RestKit' into ViewController claas's source file. Now i run the project
it shows errors like
// in this file Pods-SOCKit-prefix.pch
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import "Pods-environment.h" // Pods-environment.h file not found
// and also in this file Pods-TransitionKit-prefix.pch
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import "Pods-environment.h" // Pods-environment.h file not found
If someone knows what's the problem behind this, please explain it to me, and suggest a way to work with RestKit in Swift.
I'm not sure what the Cocoapods problem you are having. I added RestKit to my bridging header and didn't need to add import RestKit to my Swift file.
My bridging header looks like the following:
# if you are using Core Data:
#import <CoreData/CoreData.h>
#import <RestKit/RestKit.h>
# if you are using Core Data:
#import <RestKit/CoreData.h>

Resources