# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'ytl' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for ytl
pod 'Google-Mobile-Ads-SDK', '~> 7.20’
pod "AXWireButton"
pod "DGActivityIndicatorView"
pod use_frameworks! “RaisePlaceholder”
end
I created the Swift RaisePlaceholder, now I want to import in Objective-C class UIView Class.
How can I import Swift pod class into objective-C UIView Class?
Your input will be appricated.
Just simply add #objc before your Swift class like below
#objc class YourSwiftClass: UIViewController
Now in your project & targt settings, change below flags to YES
Defines Module : YES
Always Embed Swift Standard Libraries : YES
Install Objective-C Compatibility Header : YES
Now clean your project COMMAND+K now import in your objective C file like regular import
#import "YourTargetName-Swift.h"
Note: If your target name contains spaces, replace them with underscores (example: "Sample Project" becomes "Sample_Project-Swift.h"). Another point to note, in fact, that is not your project name instead your target name
Link to Apple Docs: How to use Swift code in Objective C
Related
Hi i want create one Common SDK for 3 Project which have same functionality in it but for creating that SDK we need to use some of the pod and bridging header file
we faced issue with how to configure that SDK with pod and bridging header which is used in all 3 apps to work on
Please help me how can we achieve this.
i have tried to add pod with bridging header but some how pod and bridging header not working
You can create framework project with pods and third-party library.
Note: You can't use bridging headers within a framework.
There are 2 Solution.
1. umbrella header
2. module map
Solution 1 (umbrella header):
To include the required Obj-C header you need to set it as Public: select it in the project explorer (left pane) and change the property Target Membership (left—Inspectors—pane) from Project to Public.
[Target Membership Public]
https://i.stack.imgur.com/P26rx.png
Open umbrella header (.h) and import the required header as:
[Import Headers in umbrella header]
https://i.stack.imgur.com/WEsLG.png)
This effectively makes this header public and available to both your own framework and anyone who uses it.
Note: If you import the header as a local file, i.e. in quotes, e.g. #import "objc-header.h", you likely to hit the compiler error telling you are trying to include a non-modular header.
Solution 2 (module map):
Create a file named module.modulemap in the root of your project with the following contents:
[module.modulemap]
framework module FrameworkName {
umbrella header "FrameworkName.h"
header "objc-header.h"
export *
module * { export * }
}
In case you want to keep the definitions from objc-header.h private from the users of your framework you can add private qualifier like so:
// ...
private header "objc-header.h"
// ...
In Build Setting set Module Map File to module.modulemap
Clean the build directory (⇧⌘K) and build the project (⌘B)
I'm implementing an iOS framework written on Swift. This framework has an internal dependency on a C based static library. To make it work and based on some tutorials I've made a module map similar to this:
framework module Module {
umbrella header "Module.h"
explicit module ModuleDep {
private header "header1.h"
}
export *
}
Based on that I can include C code in Swift like this:
import Module.ModuleDep
When export framework manually everything seems to work just fine. It is a sure thing, I want to have Cocoapods support for my framework with code visibility (easier to debug). The podspec, that make it work was this (some parts are omitted):
Pod::Spec.new do |s|
s.platform = :ios
s.ios.deployment_target = '12.0'
s.module_map = "Module.modulemap"
s.source_files = "Module/*.{h,swift}", "ModuleDep/*.h"
s.vendored_libraries = "ModuleDep/*.a"
s.swift_version = "5.1"
end
From my understanding, vendored_libraries is used when this is the artifact you are providing to your users and that is why I don't like this solution.
I've also tried this spec variant:
Pod::Spec.new do |s|
s.platform = :ios
s.ios.deployment_target = '12.0'
s.module_map = "Module.modulemap"
s.source_files = "Module/*.{h,swift}", "ModuleDep/*.h", "ModuleDep/*.a"
s.swift_version = "5.1"
end
but it doesn't compile.
So what is the correct way to do this? Or what have I done wrong?
Since you are using a static library as a dependency then you must specify it as a library in your podspec file. Which is why your second approach is not working because it's a library not a source file.
As mentioned in the docs vendored_libraries are for libraries that come shipped with the Pod. Also in your case that C based static library is a dependency which must be shipped with the Pod. Thus using vendored_libraries should be ok in your case.
I and my team are stuck in a strange situation involving a base project + private pods with some protocols inside.
Our problem is we can't access some of the (protocol) identifiers (defined in a private pod) from our base app code.
Apparently our problem seems to be exactly the same as the one described in these 2 stack overflow threads, but their solutions haven't worked with us.
Thread 1: Source files not found in Swift
Thread 2: CocoaPod installed but doesn't see Swift code
The skeleton we're using is this one:
Our Commons pod (with the protocol we can't see from our base app) is defined with this .podspec file:
Pod::Spec.new do |s|
s.name = "Commons"
s.version = "0.1.10"
s.summary = "Commons framework"
s.description = <<-DESC "Commons framework"
DESC
s.homepage = "http://EXAMPLE/Commons"
s.license = { :type => "Commercial" }
s.author = { "Author" => "author#mail.mail" }
s.source = { :git => "GITLAB_PRIVATE_URL/commons-iOS-Pod.git", :tag => s.version }
s.source_files = "Commons", "Commons/**/*.{h,m,swift}"
s.exclude_files = "Commons/Exclude"
end
From our base app, we have the following Podfile (to get our Commons pod onto our main xcworkspace).
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
target 'ios-appbase' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'Alamofire'
pod 'ViewDeck'
pod 'JLRoutes'
pod 'Commons', :git => 'GITLAB_PRIVATE_URL/commons-iOS-Pod.git', :tag => '0.1.4', :branch => 'develop'
pod 'RestManager', :git => 'GITLAB_PRIVATE_URL/RestManager-iOS-Pod.git', :tag => '0.1.3'
pod 'BaseClasses', :git => 'GITLAB_PRIVATE_URL/BaseClasses-iOS-Pod.git', :tag => '0.1.3'
pod 'DesignManager', :git => 'GITLAB_PRIVATE_URL/DesignManager-iOS-Pod.git', :tag => '0.1.2'
end
We've defined our protocol as public (as it's expected to be done, because it's living inside the 'Pods' project).
What else should be looking into?
PS: Not only our custom protocol is "invisible" from our main app, but also protocols defined inside Alamofire, which is another Pod included in our main app. We try to use them and XCode complains at compile time.
Thanks in advance.
Greetings.
EDIT1: Narrowing our problems, we think it's something happening in compilation time. Why? Because XCode is able to solve the faulty symbols pressing CMD+Click (two protocols defined on our Pods file structure), but the compiler can't do it and it's the one complaining with the "Use of undeclared type" error.
Whops, success (!?)
The protocol we were defining was living inside a Framework Pod, so: What were we doing wrong?
Apparently we needed to import the name of the Framework (not the class name of the protocol (!) ). Kind of a newbie error (?).
Once we typed "import Commons" on the top part of our swift file, all "undefined xxxxxx" errors disappeared.
Not sure though if we needed this specific import part because the imported Pod was a Framework project, or we just hit the nail by chance.
I have the impression some other Classes and stuff imported from some other Pods we're using, don't need an import part, and you can directly use them from the start. So our missunderstanding might have been caused by this (?).
Anyway, and as I said before, these are newbie problems using "custom pods + swift + Frameworks + somehow complex escalable .app architectures".
Let's hope this problem and its (alleged solution) sheds some light onto future developers being in a similar situation.
Greetings.
I'm trying to import the libjingle_peerconnection framework into my Xcode project, but for some reason I can't import the Objective-C header with import RTCICEServer in Swift source files. I have attempted to use header files, etc. What am I doing wrong?
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
use_frameworks!
target 'VideoRTCTest' do
pod "libjingle_peerconnection"
end
target 'VideoRTCTestTests' do
end
target 'VideoRTCTestUITests' do
end
Bridge
1. Create a xxx-Bridging-Header
Add a bridging header to your project using the method of your choice, the easiest one being creating a single .m file and answering Create Bridging Header to this dialog:
2. Reference your Pod in the bridging header
Include your files as so:
//
// Use this file to import your target's public headers that
// you would like to expose to Swift.
#import "RTCICEServer.h"
3. Objective-C exposed to Swift
Once in the bridging header, you need not import the Obj-C classes in Swift. Use these directly:
let uri = URL(fileURLWithPath: "")
let rtc:RTCICEServer = RTCICEServer(uri: uri, username: "", password: "")
print(rtc)
Another example is described here.
► Find this solution on GitHub and additional details on Swift Recipes.
My Pod file content is listed below
pod "youtube-ios-player-helper", "~> 0.1"
pod 'Google-API-Client'
I am able to import the YTPPlayer using angle brackets. This is user specific file, which should be imported with "".
#import <YTPlayerView.h>
When I try to type import "Y" nothing populates. Snapshot of HeaderSearch Path is shown below.
I did try to turn "Always Search User Header Paths" to yes, still import works only with angle brackets.
Hey you just have to import #import "YTPlayerView.h" if it does not populates write in manually as it is also given in the documentation for youtube-ios-player-helper.Build your project and it should build it successfully.
The Documentation describes step by step information to install cocoapods and how to use it.
Link for the documentation :https://github.com/youtube/youtube-ios-player-helper#installation