InstagramKit integration in swift project - ios

As suggest title, I need to use InstagramKit (3.5.0) pod (written in objective-c) in a new swift project.
So I install pod (pod install), then I create my InstagramSwift-Bridging-Header.h and add-import library:
#import <InstagramKit/InstagramEngine.h>
Then, just building this empty project, I get:
/Users/.../workspace/InstagramSwift/InstagramSwift/InstagramSwift-Bridging-Header.h:5:9:
note: in file included from
/Users/.../workspace/InstagramSwift/InstagramSwift/InstagramSwift-Bridging-Header.h:5:
-(BOOL)application:(UIApplication *)application
^ <unknown>:0:
error: failed to import bridging header
'/Users/.../workspace/InstagramSwift/InstagramSwift/InstagramSwift-Bridging-Header.h'
Expected a type Failed to import bridging header
'/Users/.../workspace/InstagramSwift/InstagramSwift/InstagramSwift-Bridging-Header.h'
What could I miss?

After a lot of discussions with #eric-d, I probably find the problem in my podfile that was:
target "InstagramSwift" do
pod 'InstagramKit', '3.5.0'
end
So I deleted project and start again from an empty project using Podfile:
use_frameworks!
platform :ios, '8.0'
pod 'AFNetworking', '~> 2.5'
pod 'InstagramKit', '3.5.0'
Than I manually created SwitBridge.h and linked it in build settings.
Finally, in any swift file I can use instagramKit module, for example:
import InstagramKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let instagramEngine: InstagramEngine = InstagramEngine.sharedEngine()
}
}
Probably, problem was that platform setting is missing.
edit
Also,
"use_frameworks!"
thanks to this answer.

Related

iOS - Add Swift pod to Objective-C project

Hello I'm working on an old Objective-C project, that has 30+ pods dependecies, all written in Objective-C.
I'm trying to add a Swift pod, this one in particular :
pod 'CSV.swift', '~> 2.4.3'
# ...
# other Objective-C pods ...
# ...
Because I would like to continue new developments in Swift.
But I cannot make it work. If I add use_frameworks!, I get an error at pod install :
The 'Pods-myProject' target has transitive dependencies that include static binaries: (/myProjectPath/Pods/ObjcPod/ObjcPod.framework)
And if I remove use_frameworks!, I get tons of compilation errors, here are some :
Undefined symbol: protocol descriptor for Swift.UnicodeCodec
Undefined symbol: dispatch thunk of Swift.UnicodeCodec.decode<A where A1: Swift.IteratorProtocol, A.CodeUnit == A1.Element>(inout A1) -> Swift.UnicodeDecodingResult
I don't know what I could try otherwise, any help would be much appreciated !
This way you can use swift pod in objective c project try this solution.
Write in your pod file
target 'YourProjectName' do
use_frameworks!
pod 'CSV.swift', '~> 2.4.3'
// Here you can add mode pod as per your requirement Like
pod 'Firebase/Core'
pod 'Fabric'
pod 'Crashlytics'
end
Then Run Pod Install.
For import write this
#import CSV;
And then you have access of your CSV pod files.

Using MapboxNavigation iOS with Xcode 10

Is there any possibility to use MapboxNavigation (version 0.21 or 0.22) iOS with Xcode 10. On its Github and CocoaPods site is stated, that it can only be used with Xcode 9, but a few issues on Github mention the (successful) use of Xcode 10 with MapboxNavigation.
However, I tried to install MapboxNavigation via CocoaPods using Xcode 10 and get a bunch of errors:
/Users/Paul_Obernolte/Library/Developer/Xcode/DerivedData/pq-app-v2-gynuaxsohvqddqegrvemywowchkr/Build/Products/Debug-iphonesimulator/MapboxDirections.swift/Swift Compatibility Header/MapboxDirections-Swift.h:171:9: error: 'MapboxDirections/MapboxDirections.h' file not found
#import <MapboxDirections/MapboxDirections.h>
^
<unknown>:0: error: could not build Objective-C module 'MapboxDirections'
Is there any workaround to avoid this errors using Xcode 10?
Edit: Here is my Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
EXPO_CPP_HEADER_DIR = 'ExpoKit'
target 'pq-app-v2' do
pod 'MapboxDirections.swift', '~> 0.23'
pod 'MapboxMobileEvents',
:git => 'https://github.com/mapbox/mapbox-events-ios.git',
:commit => "79d29f1df5a9187481f5c9ac8fa13430d1f04139"
pod 'MapboxNavigation', '~> 0.21.0'
... (more Pods)
end
I need to download MapboxMobileEvents separately because of this issue: https://github.com/mapbox/mapbox-events-ios/pull/85
target 'pq-app-v2' do
use_frameworks!
... (more Pods)
end
change code in pod file if "use_frameworks!" is commented than put it uncommented as above.

Swift Unit Test Error - framework not found AWSCore for architecture i386

I have Swift 2.3 project working fine with AWS Libraries. I just tried to create a sample unit test for this and I get this error. It seems my unit test class cannot find the frameworks I installed using a Podfile
This is the unit test class
import XCTest
import UIKit
#testable import safetyv1
class OffenceFormVCTests: XCTestCase {
var vc:OffenceFormVC!
override func setUp() {
super.setUp()
// called first
vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("OffenceFormVC") as! OffenceFormVC
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
}
This is the error I get when I do Product > Build for > Testing
And my build settings
Podfile
Anyone knows how to fix this issue? Thanks a lot!
I had the same problem it seems to be an easy fix. Just add your testing target in your podfile as another target withe same pods.
Your podfile should contain something like this:
target: 'safetyv1Tests' do
pod 'AWSCore'
pod 'AWSS3'
end
For Carthage you need to add the frameworks to the test target
Greetings,
Alex
I issue the exact same problem and pass one day to find the answer.
Problem is that when you add your project with cocoapod, you add pod to your project only.
So to solve this issue you need to add this in your PodFile:
target :'YourPojectTests' do
pod 'AWSAutoScaling'
pod 'AWSCloudWatch'
pod 'AWSCognito'
pod 'AWSCognitoIdentityProvider'
pod 'AWSDynamoDB'
pod 'AWSEC2'
pod 'AWSElasticLoadBalancing'
pod 'AWSIoT'
pod 'AWSKinesis'
pod 'AWSLambda'
pod 'AWSMachineLearning'
pod 'AWSMobileAnalytics'
pod 'AWSS3'
pod 'AWSSES'
pod 'AWSSimpleDB'
pod 'AWSSNS'
pod 'AWSSQS'
end
and replace "YourProjectTests" by your project tests name bundle
Just need to do :
pod update
And open your project.workspace on Xcode to get it working.
Safe check is to go in your projecNameTests settings and check that all -framework are set in linker section as shown like in yourProject settings
Enjoy
I was able to work around of this problem by setting FRAMEWORK_SEARCH_PATHS of my test target to
$(inherited)
"$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/AWSCore"
I can't understand Xcode adds -framework AWSCore to test target linker (OTHER_LDFLAGS is empty).

Can't get GoogleMaps SDK to work on Xcode Test Target (works on App Target)

The Setup
I have successfully integrated the GoogleMaps SDK into my Swift 2 project using CocoaPods.
My setup is pretty much that suggested by the Ray Wenderlich tutorial on the subject.
The only difference I can find is, I have to add this line to AppDelegate:
import UIKit
import GoogleMaps // <- THIS LINE
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
...
...in order to use the framework's classes. The tutorial suggests importing:
#import <GoogleMaps/GoogleMaps.h>
...to the bridging header instead.
The app works without problems.
The Problem:
When I tried to run the test target auto-generated by Xcode, I get the error:
No such module 'GoogleMaps'
...pointing at the to the swift import statement in AppDelegate above.
So, I decide to switch to the way it is in the tutorial instead: I comment out the line import GoogleMaps in AppDelegate.swift and add an Objective-C-style import statement to the bridging header.
However, I can not get it right:
If I use: #import <GoogleMaps/GoogleMaps.h> or #import "GoogleMaps/GoogleMaps.h", it gives me:
Use of unresolved identifier 'GMServices'
at AppDelegate.swift when building the app target.
If I use: #import "GoogleMaps.h", it gives me:
'GoogleMaps.h': file not found
at the bridging header.
I have tried the solution in this answer, but the results are (puzzlingly) the same...?
Next, I checked the value of Build Settings / Search Paths / Framework Search Paths for both targets (app and tests). The app target had the entry:
"${PODS_ROOT}/GoogleMaps/Frameworks"
...which the test target lacked, so I added it, and reverted to the swift-style import (the only one that works at least when building the app target), but I still get:
import GoogleMaps <! No such module 'GoogleMaps'
How can I run tests for my app??
So, it turns out all I had to do is fix the Podfile (and run pod install), as explained in this answer.
My old pod file:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.1'
def import_pods
pod 'GoogleMaps'
end
workspace 'MyWorkspace'
xcodeproj 'MyApp/MyApp.xcodeproj'
target : MyApp do
xcodeproj 'MyApp MyApp.xcodeproj'
pod 'GoogleMaps'
end
My current pod file:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.1'
def import_pods
pod 'GoogleMaps'
end
workspace 'MyWorkspace'
xcodeproj 'MyApp/MyApp.xcodeproj'
target 'MyApp', :exclusive => true do
xcodeproj 'MyApp/MyApp.xcodeproj'
import_pods
end
target 'MyAppTests', :exclusive => true do
xcodeproj 'MyApp/MyApp.xcodeproj'
import_pods
end

Using dependency in swift module (framework)

I am trying to create a swift module (Cocoa Touch Framework) with reusable code inside the environment set up by cocoa pods which includes third party libraries written in Objective-C (namely here Restkit).
Unfortunately I am not able to use Restkit in the module I create.
Here's what I did to create the module:
File -> New target: Cocoa Touch Framework, Language: Swift, Project: MyProject, Embed in Application: MyProject
In the "Info" tab of the project settings in the "Configurations" section I define the Pods.debug and Pods.release xcconfig file for my newly created target.
In the header file, which Xcode automatically created for me, networkModule.h, I add the following line:
#import <RestKit/RestKit.h>
Result: When trying to compile I get the error "include of non-modular header inside framework module 'networkModule'"
I have set the flag for "Allow Non-modular Includes in Framework Modules" to YES in the build settings for the Project Target and the Module/Framework target.
I went to the Cocoa pod project and have tried setting the visibility of the RestKit.h Header file to "Public" in the target membership (which of course is not a good solution to mess with the cocoa pods environment)
I am not able to compile. I still get the same error.
Is it possible in the first place to create a Cocoa Touch Framework with dependencies to a cocoa pod managed framework?
Btw. My first idea of creating a private cocoa pod didn't work out as well, as it doesn't seem to be supported, although I am using the prerelease of cocoa pods 0.36 with support for swift.
You should be able to make your won private Pod. You just need to make a podspec for it. Here is an example of one.
Pod::Spec.new do |s|
s.name = "Commons"
s.version = "1.0.0"
s.summary = "Common code for my iOS projects."
s.license = {:type => 'Commercial', :text => "Copyright (c) Dan Leonard(Or Your Name?). All rights reserved." }
s.source = { :git => "https://github.com/PATHTOPOD", :tag =>
s.version.to_s }
s.homepage = "https://github.com/PATHTOPOD"
s.requires_arc = true
s.ios.deployment_target = '9.0'
s.subspec 'Core' do |ss|
ss.source_files = '*.swift'
end
s.subspec 'Menu' do |ss|
ss.source_files = 'Menu/*.swift'
ss.resources = ['Menu/*.storyboard', 'Menu/*.xcassets']
ss.dependency 'Alamofire'
end
end
Then Inside your project you just have to do pod init open your podfile that was just created and add this
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'YOURPROJECT.xcodeproj'
platform :ios, '9.0'
use_frameworks!
pod 'Commons', git: 'https://github.com/PATHTOPODPROJECT'
#pod 'Commons', :path => '/Users/YourUser/Path/To/Project/commons'
pod 'KeychainSwift'
pod 'SQLite.swift', git: 'https://github.com/stephencelis/SQLite.swift.git'
Now in this example Podfile Commons is stated twice the second is commented out. If you uncomment it and comment out the first then do pod install in your projects folder from the terminal. This will make a DevelopmentPod which is a pod that is local. This way you can make changes to the pod locally within Xcode. No switching and pod installing every time you make a change.
You will import the pod just like any other by putting
import Commons not #import <Commons/Commons.h> That is how you do it in Objective C not Swift
Once you have a working version commit it to git hub and point your project to the the github version.
Hope this helps.

Resources