I have created a new single-view swift project, and then added a pod file (for MWPhotobrowser) and installed it.
I can now do import MWPhotobrowser on top of ViewController.swift file and use this framework without problems.
but I need to make some changes to this pod by adding extra properties to MWPhotoBrowser.h file, one of these properties is a reference to ViewController.swift class.
I am aware of the following:
A) It's not a good practice to make changes on pod frameworks since pod update will overwrite these changes.
B) I can fork the main github repo and point cocoa pods to my fork.
C) I can download the frameworks form github and do not use cocoa pods at all.
But for my specific case, I need to access ViewController class from inside cocoa pods ?
things I've already tried:
1) Defines Modules set to yes in the main project as well as in the pods project
2) #import "ProjectName-Swift.h" gives file not found
3) dragged the file ViewController.swift into Pods project (the blue icon in project navigator), this gave me: Include of non-modular header inside framework module 'MWPhotoBrowser.MWPhotoBrowserPrivate' build error, which I've tried all possible solutions on SO to solve this error but to no avail ...
4) marked ViewController class with #objc attribute
and here is a clean sample project.
how can I access ViewController swift-based class from inside pods ?
Related
I am trying to install this library without using Pods. In their git, they explain that it's possible to do it by dragging the .xcodeproj file on the user project:
Yes you can copy it the classes like before. However it's more
comfortable to drag the xcodeproj to the project. It's not recommended
to drag the sources themselves, as this will make updating Chrats in
your project more difficult.
By dragging the project I get an error When I try to import the module:
No such module 'Charts'
I also selected my project -> Build Phases -> Link Binary With Libraries and added the Charts.framework. That didn't solved the problem.
I think to use any of the cocoa pods you have to build a header file as maybe the code that you are going to use might be in objective C and you might be using swift.
Simply create briding header file with named
"projectname-bridging-header.h" at root of your project.
Now got to build setting of project and in that do below changes:
Install objective-c compatibility header : YES
objective-C briding header : set path of your bridging header like
"projectname/briding header file name.h"
once its done import all your objective c file of pods which u want
use in swift app.
Note : if required then set the path as a recursive in the resource headers and Swift compiler search section.
let me know if any issues :)
I have a library that I'm using through Cocoapods, and I'm modifying it slightly. I have a class I've created in my normal project (outside of Cocoapods) that I want to use in the Cocoapod, but when I try to import the file it says that file doesn't exist.
As pods are seemingly achieved through a separate project within the same workspace, I assume that's the reason why I can't access it. How would I access it, however? Do I have to import the file separately into the Pods project and then maintain two separate versions? Or is there a better way?
I added pod 'CrittercismSDK' to my Podfile and ran pod install, it finished with no error, all good.
Using import Crittercism gives No such module error. I looked into the Pods/ directory, there source code is there; however, the Pods project doesn't have a target called Pods-MyProject-Crittercism (but it does have targets for each dependency).
Build keeps failing because the import isn't found. What am I doing wrong?
PS: I'm using use_frameworks! directive in my Podfile, and I have another obj-c library that works fine, so I don't know why this one isn't working.
While this is not a general answer, I have found that:
Not using #use_frameworks
Using a Bridging-Header.h containing #import "Crittercism.h"
Not importing CrittercismSDK in the Swift class, but merely executing Crittercism.enableWithAppID("appId") does the trick.
See if below steps helps in your case. What version of pod/Xcode in use? It will be great if you can share your pod file, thanks.
Install dependencies using Cocoapods and the use_frameworks! flag.
As you need to use a Objective-C dependency, create a Bridging header. You can create one easily by importing an Objective-C class to your Swift project, than remove it (the wizard should ask you if need a bridging header). Otherwise, create a new header file. Then, navigate to your target configuration and enter the name of your file in Swift Compiler - Code Generation > Objective-C Bridging header.
Still in your target configuration, add a new entry in Search Paths > User Header Search Paths: Pods as value and flag it as recursive.
Remove any import instruction from your code, relative to your Objective-C library.
Build your project. You should have a success.
I am working on iOS 8 extension. I read many manuals and all of them just show how simple add extension to your app, and seems that's enough.
But here are many pitfalls:
After adding your extension you will need to import some of your classes to view controller that were created when you added new extension target. The big use here that you will need add all of them and if you have huge project it's not a simple task. Solution can be select extension target then in Build Phases -> Compile Sources press plus button and add all .m files to your target using hot key CMD+A.
After adding all files you can see that some of method wont work, and you can see this error: 'sharedApplication' is unavailable: not available on iOS (App Extension) so the solution can be a macros that check ifndef Extension then we can invoke sharedApplication code.
#import <Foundation/Foundation.h> vs #import <UIKit/UIKit.h>. So I have not figured out with this issue but when I replaced Foundation with UIKit it works for me and all related issues go away.
CocoaPods. All of us are using CocoaPods so if your extension need to use some part of your project code and that code use CocoaPods library then you need to add link_with 'ProjectTarged', 'ExtensionTarget' to Pod file and make pod install again to bind your libraries with new extension target.
So this is a main points I faced with. Maybe someone can suggest how to solve that issue, as I said I just import one needed file to extension view controller. The imported file contain some libraries like AFNetworking, RestKit and other nested classes from the main project. I need this class to invoke few methods with passing data from extension to my backend server. So one file but many issues.
you can use this in your Podfile to prevent "Require only App-Extension-Safe API". Just put it to the end of your Podfile.
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
end
end
end
1) You only need to add files to the extension target that you actually intend on using. I would recommend only pulling over what you need by finding the files and in the File Inspector, adding them to both targets.
2) Yep that's right. You'll need to update libraries that check that for you or fork them and fix them yourself.
3) I think you're referring to the default templates when creating one of the app extensions. Yes, you need to use UIKit not Foundation. Foundation will work for iOS or OS X, but clearly isn't enough if you are making a UIKit application.
4) The link_with command will make all pods in your Podfile link to all of the targets listed. If that's what you need, then, fine, do that. If you just need a small subset of pods for your extension, use the following:
target 'whateverTarget', :exclusive => true do
pod 'SomePod'
end
To remove sharedApplication issue from CocoaPods Libraries you just need to change Build Options within Build Settings for your pod.
Just type to search Require Only App-Extension-Safe API and then change the value to NO as it is on the image below:
Propably you will need to do this for every of your pods.
Added a new class and methods to the existing code in an imported pod.
I checked everything I could in the Utilities for this new class.
Location of .h and .m file is selected as 'Relative to project' like all other files in this pod
actual files are in the same path as the other file of this pod
target membership is same as pod.
Xcode is not seeing the addition of the new class (h file in an import statement in the project using the pod).
Not sure why it doesn’t work for you, but aside from that you should not modify the Pods.xcodeproj. CocoaPods assumes it has control over it and will wipe out your changes on the next pod install or pod update. (Maybe that’s the problem your seeing?)
Either add the custom class to your own project, extend the library with categories in your own project, or have a fork of the library where you push your changes to (possibly by using the :local directive in your Podfile).