Using RestKit in Swift - ios

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>

Related

Objective-c class exposed via bridging header not visible from swift when archiving release

In my react native project, I try to expose a swift function to the javascript code. It works well in debug mode, but when trying to archiving I get a Use of undeclared type RCTEventEmitter error on my swift file.
The RCTEventEmitter is imported in my RNUtils.m file, and in the bridging header.
So I guess somewhere in the archiving, something fail with the bridging header, but I have no idea where.
If I ask for a non existing import, it will tell me that it can't compile the bridging header, so the file is taken into account during the build.
// Utils.m
#import "React/RCTBridgeModule.h"
#import "React/RCTConvert.h"
#import "React/RCTEventEmitter.h"
#interface RCT_EXTERN_REMAP_MODULE(RNUtils, RNUtils, RCTEventEmitter)
#end
// Utils.swift
import Foundation
#objc(RNUtils)
class RNUtils: RCTEventEmitter {
// my native code emitting events
}
// MyApp-Bridging-header.h
#ifndef MyApp_Bridging_Header_h
#define MyApp_Bridging_Header_h
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
#endif
react-native 0.61.5
xcode 11.5
Swift 5
It appears I needed to add ìmport React` in every swift file. It's archiving fine now.

Importing ObjC files into Swift

I want to import files from this library, I copied and pasted the following .h and .m files from the ObjC library into my Swift project:
AppDelegate.h AppDelegate.m
ViewController.h ViewController.m
SPUserResizableView.h SPUserResizableView.m
Upon copying and pasting these files into my project, Xcode asked me to create a bridging header file, I then put the following lines into that bridging header file:
#import "ViewController.h"
#import "SPUserResizableView.h"
#import "AppDelegate.h"
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
I tried to build my project, but build failed. I got many unknown type errors and such, which I assume is because the system is not recognizing the ObjC code. I also got this line of error:
failed to emit precompiled header '....../Project-Bridging-Header-swift_24D19ORYKRN0-clang_1KQCLSEAC5RDY.pch' for bridging header '......./Project-Bridging-Header.h'
How do I resolve these errors? What else do I need to do to use the Objective C library in my swift code?
Why you import AppDelegate.h and other
just use this class (SPUserResizableView.h SPUserResizableView.m)
and in Bridge file
^ #import "SPUserResizableView"
in your BridgingHeader just add
#import "SPUserResizableView.h"
dont copy other projects AppDelegate and ViewController. just copy SPUserResizeableView.h and .m file

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.

Chartboost and swift integration

Ok, this is the first time I am trying to integrate chartboost and swift, so I will start from the beginning, maybe I missed something. First I have imported chartboost framework into my project, and then manually created the .h file, which I named BridgingHeader.h I added the needed import statements so that file looks like that now:
#ifndef appname_BridgingHeader_h
#define appname_BridgingHeader_h
#import <Chartboost/Chartboost.h>
#import <Chartboost/CBNewsfeed.h>
#import <CommonCrypto/CommonDigest.h>
#import <AdSupport/AdSupport.h>
#import <UIKit/UIKit.h>
#endif
I tried to build, everything went fine, but I noticed that it does not actually import this file. Hence I went to my project build settings, located Swift Compiler - Code Generation and found Objective-C Bridging Header and named it as appname/BridgingHeader.h . Now I am sure it did find the file and tried to import chartboost files, because I got 56 errors, of which all are in the chartboost files. Erros are such as "function definition is not allowed here" or "expected a type". The last error says that it failed to import bridging header. Anyone knows or has any ideas how to make this work?
Thanks
Ok, I my problem.
1) UIKit import should be done as follows:
#import <UIKit/UIKit.h>
#ifndef appname_BridgingHeader_h
#define appname_BridgingHeader_h
#import <Chartboost/Chartboost.h>
#import <Chartboost/CBNewsfeed.h>
#import <CommonCrypto/CommonDigest.h>
#import <AdSupport/AdSupport.h>
#endif
2) for the path, I should just went to the bridging file, in the file inspector copy the full path and paste it in the Swift Compiler - Code Generation.

Resources