I'm using ObjC pod in my Swift project.
I import the library in my .swift file.
The ObjC project have Delegate and DataSource.
I implement the methods for use without any errors, but when I build and run the project, the app crashes with error that the methods of the DataSource has not been implemented.
reason: ''numberOfContacts' Not implemented'
It looks like the ObjC pod doesn't read the implemented methods in my .swift file.
It executes this line:
- (NSInteger)mev_horizontalContactsNumberOfContacts
{
if ([_dataSource respondsToSelector:#selector(numberOfContacts)]) {
return [_dataSource numberOfContacts];
} else {
NSAssert([_dataSource respondsToSelector:#selector(numberOfContacts)], #"'numberOfContacts' Not implemented");
return 0;
}
}
This is the pod: https://github.com/manuelescrig/MEVHorizontalContacts
Check if your pod file has use_frameworks!, if Yes, then just import of YOUR_OBJC_SDK will work.
// Podfile
use_frameworks!
pod 'YOUR_OBJC_SDK'
If it doesn't have use_frameworks!, then you may need to add the Bridging-Header to import all the ObjectiveC framework.
Goto Swift Compiler - Code Generation in your project Build Settings. Add the path of your bridging header file next to Objective C Bridging Header from the project root folder. It should be Your_Project/YOUR_Bridging-Header.h file.
Related
I want to use React Native Pods into one of my iOS Apps which is built using Swift. I have bundled my React Native components into ios-main.jsbundle. I am consuming the routes as shown below:
class ContentViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func loadView() {
loadReactNativeView()
}
func loadReactNativeView() {
let jsCodeLocation = Bundle.main.url(forResource: "main-ios", withExtension: "jsbundle")!
let rootView = RCTRootView(
bundleURL: jsCodeLocation,
moduleName: "YourApp",
initialProperties: nil,
launchOptions: nil
)
self.view = rootView
}
}
and in order to use React, I have done pod installation with my podFile something like as shown below:
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/#react-native-community/cli-platform-ios/native_modules'
platform :ios, '13.0'
target 'yourreactnativeapp' do
use_react_native!
end
This works fine but here's the problem, my ios file is a root git directory and so I can't go one level up... again to perform pod installation, even if I place the files into my ios directory that would mean uploading entire node modules, which doesn't seem like a good solution, is there a way that I could use something other than require_relative to install React Native pod dependencies remotely from somewhere? I am okay with uploading node modules into another git repo and then fetching it from there.
I have a static library that needs to link to other static libraries.
When I attempt to run ./gradlew common:cinteropSomeLibIos :
I always get IllegalStateException: Could not find 'libabseil.a' binary in neither of [external/lib]
my def file:
headers = SomeHeader.h
language = Objective-C
package = com.mypackage
staticLibraries = libabseil.a libMyLib.a
libraryPaths = external/lib
linkerOpts = -lObjC -all_load
Everything works within AndroidStudio/IntelliJ but when using the command line interface or building with bazel i consistently get the above error.
I tried adding:
val main by compilations.getting {
kotlinOptions {
freeCompilerArgs = listOf(
"-include-binary", "$libLocation/libabseil.a"
)
}
}
as well as setting linkerOpts within the gradle file but that results in:
warning: -linker-option(s)/-linkerOpts option is not supported by cinterop. Please add linker options to .def file or binary compilation instead.
Is there any way to get this working or at least to call the cinterop task in a way that the relative paths in the .def file will work?
I'm trying to use cocoapods framework in Kotlin Multiplatform project.
So I
added framework to Pods file.
ran pod install.
created .def file
added cinterop config in build.gradle
./gradlew cinteropFirebaseIos runs successfully. It generates .klib so I can see classes in kotlin code.
But when I'm trying to run iOS app build fails with message:
Showing Recent Messages
> Task :app:linkDebugFrameworkIos
ld: framework not found FirebaseDatabase
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors
Here is my config in build.gradle
fromPreset(presets.iosX64, 'ios') {
compilations.main {
outputKinds('FRAMEWORK')
cinterops {
firebase {
def proj = "${System.getProperty("user.home")}/Projects/kmpp"
def pods = "${proj}/iosApp/Pods"
defFile "${proj}/app/src/iosMain/c_interop/libfirebase.def"
includeDirs "${pods}/Firebase",
"${pods}/Firebase/CoreOnly/Sources",
"${pods}/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers"
}
}
}
}
here is my .def file:
language = Objective-C
headers = /Users/oleg/Projects/klug/crckalculator/iosApp/Pods/FirebaseCore/Firebase/Core/Public/FIRApp.h /Users/oleg/Projects/klug/crckalculator/iosApp/Pods/FirebaseDatabase/Firebase/Database/Public/FIRDatabase.h /Users/oleg/Projects/klug/crckalculator/iosApp/Pods/FirebaseCore/Firebase/Core/Public/FirebaseCore.h
compilerOpts = -framework FirebaseDatabase
linkerOpts = -framework FirebaseDatabase
How can I figure out what is wrong ? Did I miss something in .def file ? In build.gradle ?
There are two problematic moments here:
full paths to C headers in .def file are usually not desirable, instead passing includeDirs to Firebase installation, like in https://github.com/JetBrains/kotlin-native/blob/c7c566ce0f12221088a8908b6dc8e116c56a931b/samples/gtk/build.gradle#L22 would be helpful
linking problem comes from the similar issue - linker just got no idea where to look for framework libraries, so passing to compilations.main.linkerOpts smth like -F /Users/oleg/Projects/klug/crckalculator/iosApp/Pods/FirebaseCore/ shall help, see for example https://github.com/JetBrains/kotlin-native/blob/c7c566ce0f12221088a8908b6dc8e116c56a931b/samples/videoplayer/build.gradle#L15
I install Mixpanel to my project and AFNetworking doesn't work anymore and in all methods show me this error:
Use of unresolved identifier 'AFHTTPRequestOperationManager'
But Xcode have link to the class in the method, I tried pod install, pod update, clean the project and it doesn't work
In PodFile:
target 'My Project' do
pod 'AFNetworking'
pod 'Mixpanel'
end
target 'Mi ProjectTests' do
end
In Bridging-Header:
#import <AFNetworking.h>
#import <Mixpanel/Mixpanel.h>
and the last error show is:
ld: framework not found -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos
To AFNetworking 3.0 version:
let manager = AFHTTPSessionManager()
To solve the last error go to Build Settings, Other Linker Flags and remove all except $(inherited)
I had the same problem, after I update pod to the latest version of AFNetworking. There wasn't a AFHTTPRequestOperationManager anymore, so try to call this:
let manager = AFHTTPSessionManager()
Upload task with progress, in swift 3.0 like this:
let request = URLRequest(url: URL(string: "http://example.com/your/url")!)
manager.uploadTask(with: request, from: userData, progress: { (progress: Progress) in
// progress catching
}) { (response: URLResponse, object: Any?, error: Error?) in
// work with response
}
Trying to build a PlugIn for Coda 2.5 with swift.I'm getting this error:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_CodaPlugInsController", referenced from:
_get_field_types_PowPlugInViewController in PowPlugInViewController.o
_get_field_types_PowPlugIn in PowPlugin.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have cleaned my build folder.
I have created and added import statements to the project name-bridging-swift.h.
Here is a look at my project.
CodaPlugInsController.h
You can find this file here.
https://github.com/panicinc/CodaPluginKit/tree/master/Cocoa%20Plug-ins
Discription:
This header provides protocols and facilities to implement Coda
text-based, syntax validator and sidebar plug-in.
CodaPow-Bridging-Header.h
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "CodaPlugInsController.h"
PowPlugin.swift
import Foundation
class PowPlugIn: NSObject, CodaPlugIn, CodaSidebarPlugIn {
let PowBundle: CodaPlugInBundle
let PowController: CodaPlugInsController
required init(plugInController: CodaPlugInsController, plugInBundle: CodaPlugInBundle) {
self.PowBundle = plugInBundle
self.PowController = plugInController
super.init()
}
func name() -> String {
return "Coda Pow"
}
func didLoadSiteNamed(name: String!) {
}
func viewController() -> NSViewController {
return PowPlugInViewController(nibName: "PowPlugInView", plugInBundle: PowBundle, plugInController: PowController)!
}
}
PowPlugInViewController.swift
import Foundation
class PowPlugInViewController: NSViewController, CodaSidebarViewController {
let PowController: CodaPlugInsController
init?(nibName: String, plugInBundle: AnyObject, plugInController: CodaPlugInsController) {
self.PowController = plugInController
super.init(nibName: nibName, bundle: plugInBundle as? NSBundle)
}
// Xcode Says I need this.
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
I have two more source files.
ServerAndHosts.swift and
Shell.swift They don't use any of the classes in CodaPlugInsController.h. The Shell.swift file is just a set of Class functions.
Edit:
I can use swift as long as I don't subclass from the CodaPlugInsController.h or pass in an object that has been.
Swift and Obj-C versions of Project: https://www.dropbox.com/sh/bsw8cinn7kp9kfe/AAAgG_B44dbHNP5-JwJ3Amf8a?dl=0
The project compiles, so the bridging headers may not be the issue.
You fail at the linking stage, the compiler can't find a set of symbols for your current architecture.
This could either mean
1) The Coda library is not compiled for your architecture
or
2) the linker couldn't find the library at all.
I looked at your Obj-C project, and it appears the Coda library is not in the project, so I'm guessing its #2. You'll either want to move the lib into the project somehow, or add a path to the lib elsewhere on your system in your project's "library search paths"