How to use Cocoapods in Xcode - ios

I'm a beginner, just getting started with coding in Swift 5 and Xcode. I'm trying to develop a basic iOS app and want to use a cocoapod to my project.
I've managed to successfully install the cocoapod to Xcode and I can see it in Xcode. However, I can't seem to figure out where to add the relevant codes and use it.
For example, can somebody please help me make use of the following Cocoapod; "Gallery'
https://cocoapods.org/pods/Gallery
Many Thanks.

I'm not entirely sure what step you're on, but in general you add a Cocoapod with the following steps:
Add the pod to your Podfile:
pod `Gallery`
Run pod install in your project directory.
Open the generated .xcworkspace file.
Import the library when you need it in a file:
import Gallery

Related

Cocoa Touch Framework with CocoaPods dependencies

I'm trying to create a Cocoa Touch Framework.
I created a Cocoa Touch Framework
I ran pod init
I added our own CocoaPod to this, which has some dependencies itself as well.
I ran pod install.
Now when I try to build the framework (I open the .xcodeproj) I get the following warnings for each dependency.
ld: warning: directory not found for option '-F/Users/jeroen/Library/Developer/Xcode/DerivedData/OurFramework-culynvrparvtfjbjlitmammotpkf/Build/Products/Debug-iphoneos/Alamofire'
I get the following errors:
ld: framework not found Alamofire
error: Resource "/Users/jeroen/Library/Developer/Xcode/DerivedData/OurFramework-culynvrparvtfjbjlitmammotpkf/Build/Products/Debug-iphoneos/FirebaseFirestore/gRPCCertificates-Firestore.bundle" not found. Run 'pod install' to update the copy resources script.
I expect that this is because the CocoaPod files are not copied to the right place. Is that correct?
What could I do to make this work anyway?
The reason I want to do this is the following:
I have a CocoaPods project which is a regular Xcode project with only Swift classes and some view controllers. We want to make this available as closed source. So I'm hoping that including this pod in a Cocoa Touch Framework would still make all public functions of its pods available to the user.
If there are other suggestions, they are welcome!
Thanks in advance.
The first point I got is you used .xcodeproj after pod installation. Please note that once you install pods there is one more file is created with an extension .xcworkspace you need to use this file to open project and your future work should be done in this file.
Okay, so all the problems I had with setting this up seemed to be Xcode-related.
Basically what I did to get this working is the following:
Create a Cocoa Touch Framework through Xcode's File > New > Project ....
Using terminal, navigate to the framework's root folder (the folder with the YourFramework.xcodeproj-file).
Run pod init.
Add the necessary CocoaPods to the Podfile.
Run pod install.
Make sure you close the YourFramework-project that's probably open in Xcode.
From here on my problems started occurring. Opening the YourFramework.xcworkspace worked, but in the left-side navigator of Xcode, I could only expand the Pods-project, not the Framework-project; it seemed to be empty. Building didn't work either.
To solve this (So, just the regular steps to solve Xcode problems):
Close Xcode.
Delete derived data.
Open the YourFramework.xcworkspace again.
Clean the build folder.
Now it maybe builds, or not. In my case it didn't and got 100s of problems related to the Swift language being unavailable. I created a framework without any source files, just imported CocoaPods. To solve this create a Swift file in the framework which imports at least Foundation.
Now it should build.

How can we share sdk/Framework which is having library, to some other project?

I want to share framework in another app. I am facing issues when I have some libraries/pods like Alamofire in my framework. what is the solution of this problem? how can i use that library in framework? Also i tried to install Alamofire pod in to the other app in which i have added framework, and tried to access in my framework class but this was not accessible. please guide me how to do it. Thank you
You can use Cocoapods to achieve that. Basically, cocoapods will create a framework for you from the source files that you define and will also install the appropriate dependencies that you define in the target project when the target project does pod install.
Apart from cocoapods, you can also use Carthage which is also a dependency management tool.
You can read more about cocoapods here and how to create a new pod here

How can i use SwiftSocket?

Hi I am newbie at iOS development.
Do you know how to use SwiftSocket?
link is here.
https://github.com/swiftsocket/SwiftSocket
I followed install guide (use cocoapod in Terminal)
chage directory to project file root
pod init
open podfile and insert pod 'SwiftSocket'
pod install
but I can't import SwifSocket in ViewController class :(
(I tried it at xcworkspace)
What's the problem??
Can't import SwiftSocket framework
and project podfile is here.
It's working , but you should close the project while pod install , open from workspace and importantly wait until project finishes indexing
Try to build (not run) your project first using ⌘+B.

Include CocoasMQTT library in swift framework project

I am pretty new to swift and iOS development. I am trying to write a framework using swift 2.0. I need to import the CocoasMQTT library in my framework. I am using cocoa pods approach for this and i added
use_frameworks!
pod 'CocoaMQTT'
in my pod file. After this I pod install. Now in my Pods directory I can only see debug.xconfig and release.xconfig files(in xcode directory view). I think this should have worked but I am unable to import the library in my swift classes as it says that "No Such module 'CocoaMQTT'" when i try
import CocoaMQTT
in my code.
Can anyone explain if I am doing something wrong. P.S., as I have included use_frameworks! and I am using iOS version 9 for development so I think I don't have to write the Objective C bridge header.
I had same problem to. My problem cause about using CocoaPods. I think you open .xcodeproj file by Xcode but if you install pods you must open .xcworkspacefile. You should look raywenderlich's forum for using cocoapods.
https://www.raywenderlich.com/97014/use-cocoapods-with-swift
Close your xcode after pod install, and open the .xcworkspace file generated by Cocoapods.

How to use openCV in iOS? I just can't import the framework correctly

How can I add opencv2 correctly to Xcode?
I just download from the website the opencv2.framework.zip,
and then I unzip the opencv2 ,finally appears opencv2.framework.
and then I build an xcode project, choose ios single view.
then I try to add opencv2.framework to the project
then I compile the project, It shows that:
what's happening here?I'm new here and I just can't figure out a solution. Thank you very much for your help!
I've put together a guide to use OpenCV using the .framework file (if you prefer it over cocoa pods as suggested above) you may have a look here. It works for both OpenCV2 iOS and the newer OpenCV3 iOS.
http://kurtjacobs.weebly.com/computer-vision/up-and-running-with-opencv-30-for-ios
Good luck!
You can download the opencv2 .framework, then in Xcode project, click the targets selected build phases. Click link Binary with libraries, click add other and select the .framework, clang.
Try and use Cocoapods to install it. If you haven't used Cocoapods before, it is a "CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects." More information is available on its website HERE.
To install OpenCV using Cocoapods, add pod 'OpenCV' to your pod file, and use the command pod install. Please refer to the OpenCV for iOS Cocoapods Readme page (https://cocoapods.org/pods/OpenCV) for more details.

Resources