leoho0722
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    ###### tags: `第13屆IT邦鐵人賽文章` # 【在 iOS 開發路上的大小事-Day11】透過 CocoaPods 來管理第三方套件 # 前情提要 一般在開發的時候,有些功能可能自己寫不出來,但是網路上已經有別人寫好的,那我們只需要將其引入到專案內,就可以使用了 常見的套件管理工具有:(1)CocoaPods (2)Carthage (3)Swift Package Manager (SPM) ## 今天要來介紹的是 CocoaPods 第三方套件管理工具 CocoaPods 是基於 Ruby 語言所開發的套件管理工具 在 macOS 中有內建 Ruby 系統,所以就可以直接在 Terminal (終端機) 中輸入指令 ![](https://i.imgur.com/jwuqrpm.png) ▲[CocoaPods 官網](https://cocoapods.org/) # 開始安裝 CocoaPods 囉 打開電腦中的 Terminal,輸入下面的指令 ``` sudo gem install cocoapods ``` 輸入電腦密碼,輸入過程是不會顯示的! 輸入完之後,就按下 Enter 讓他去跑,安裝過程可能會需要一點時間 ![](https://i.imgur.com/46hoGri.png) 這裡由於我電腦中已經有安裝過 CocoaPods,所以就很快跑完了 接著透過 Terminal 指令切換到專案資料夾內,這邊專案我是在桌面創建的 ``` 範例(1):cd /Users/電腦使用者名稱/Desktop/你的專案名稱 範例(2):cd ~/Desktop/你的專案名稱 cd /Users/leoho/Desktop/CocoaPodsDemo ``` 然後輸入下面指令,在專案內初始化 CocoaPods ``` pod init ``` ![](https://i.imgur.com/eQhAPpa.png) 然後打開專案資料夾內的 Podfile 檔案 ![](https://i.imgur.com/svuKKGC.png) 在「use_frameworks!」裡輸入要安裝的套件,這裡示範安裝「IQKeyboardManagerSwift」套件 ``` target 'CocoaPodsDemo' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! pod 'IQKeyboardManagerSwift' # Pods for CocoaPodsDemo end ``` ![](https://i.imgur.com/C5pZgKV.png) 接著在 Terminal 中輸入指令 ``` pod install ``` ![](https://i.imgur.com/fplB003.png) 這樣就完成 IQKeyboardManagerSwift 這個套件的安裝了 接著打開專案資料夾中的 `專案名稱.xcworkspace` 檔案 (紅框處),這個是安裝完套件後 CocoaPods 自動產生的檔案,以後要開發都只能開這個檔案! ![](https://i.imgur.com/vdMTiF0.png) ### Podfile 裡的套件版本控制 ```ruby= # 邏輯運算符寫法 pod 'IQKeyboardManagerSwift' # 這是一般的寫法,不指定版本,會自動安裝最新版 pod 'IQKeyboardManagerSwift','6.5.6' # 這是指定安裝套件的第 6.5.6 版 pod 'IQKeyboardManagerSwift','> 6.5.6' # 這是指定安裝套件第 6.5.6 版以後的最新版本 pod 'IQKeyboardManagerSwift','>= 6.5.6' # 這是指定安裝套件第 6.5.6 版或以後的最新版本 pod 'IQKeyboardManagerSwift','< 6.5.6' # 這是指定安裝套件第 6.5.6 版以前的最新版本 pod 'IQKeyboardManagerSwift','<= 6.5.6' # 這是指定安裝套件第 6.5.6 版或以前的最新版本 # 樂觀操作符寫法 pod 'IQKeyboardManagerSwift','~> 6.5.6' # 這是指定安裝套件的第 6.5.6 版及第 6.6.0 版以下的版本 (不包含第 6.6.0 版或更新版本) pod 'IQKeyboardManagerSwift','~> 6.5' # 這是指定安裝套件的第 6.5 版及第 7.0 版以下的版本 (不包含第 7.0 版或更新版本) pod 'IQKeyboardManagerSwift','~> 6' # 這是指定安裝套件的第 6 版及第 7.0 版以前的版本 (不包含第 7.0 版或更新版本) ``` 最後,每種套件的安裝方法都不太一樣,安裝前記得看一下作者的安裝說明喔! # 參考資料 1. [What is a Podfile? (CocoaPods.org)](https://guides.cocoapods.org/using/the-podfile.html)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully