[Swift] Beginners stumbled upon installing CocoaPods & installation procedure

This title

Nice to meet you, I've been learning swift for a little over two weeks. I have a library I want to use, and when I tried to install CocoaPods for package management, there were some clogging points, so make a note of it. The installation procedure is also posted while eliminating the error. Sorry to trouble you if you make any mistakes, but please leave a comment.

environment

macOS Catalina 10.15.6 xcode 11.1

Installing CocoaPods

Start the terminal and install cocoapods with the following command.

sudo gem install cocoapods

However, I immediately got the following error here.

ERROR:  Loading command: install (LoadError)
    dlopen(×××××××××/.rbenv/versions/2.5.0/lib/ruby/2.5.0/x86_64-darwin16/openssl.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: ×××××××××/.rbenv/versions/2.5.0/lib/ruby/2.5.0/x86_64-darwin16/openssl.bundle
Reason: image not found - ×××××××××/.rbenv/versions/2.5.0/lib/ruby/2.5.0/x86_64-darwin16/openssl.bundle ERundefined method `invoke_with_build_ar

A solution to this error can be found in this article,

$ rbenv uninstall 2.5.0
$ rbenv install 2.5.0

I was able to solve it by doing. Replace the version with the one in your environment in the error content. In my case, the error content was 2.5.0, so I specified it.

Then run the installation again.

sudo gem install cocoapods

This time it was successful.

Configuration

Set up library information.

pod setup

Then move to the project. I am here What level is the project? It seems that it refers to the hierarchy with project name.xcodeproj. I made a mistake and went to the lower level sweat

Creating a podfile

When you execute the following command, a file called Podfile will be created in the current hierarchy (project).

pod init

Edit podfile

It is as follows in the initial state.

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'UIMenuItem' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for UIMenuItem

end

This time I wanted to use a library called FloatingPanel, so edit it as follows.

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'UIMenuItem' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for UIMenuItem
  pod 'FloatingPanel'  #Postscript

end

Added pod'FloatingPanel'

When you're done editing, save and close the file.

Library installation

By executing the following command, the library will be installed according to the description in the Podfile.

pod install

Try using the library

I made a slight mistake here and got stuck.

So far Project name.xcodeproj I opened the file and worked on it, but the library could not be used there.

After investigating, after the introduction of CocoaPods, You will be working on a file called project name.xcworkspace. Since it is made in the same hierarchy, please open this without making a mistake.

Import the library.

ViewController


import UIKit
import FloatingPanel //Import library


class ViewController: UIViewController {
    //Abbreviation

Many articles ended here, but in my case

No such module 'FloatingPanel'

I got the error. The solution to this error is here (https://stackoverflow.com/questions/31065447/no-such-module-when-i-use-cocoapods). It's a fairly old question on stackoverflow, but when I tried it as it was, the error disappeared.

I will write the procedure.

First, find and click Manage Schemes ... by referring to the image below. スクリーンショット 2020-10-16 3.42.00.png

Check the library name in the menu below. This will eliminate the error. スクリーンショット 2020-10-16 3.48.10.png

that's all.

Recommended Posts

[Swift] Beginners stumbled upon installing CocoaPods & installation procedure
What I stumbled upon when installing Laravel-filemanager
eclipse installation procedure
What I stumbled upon when installing Ruby on Ubuntu