Skip to content

Installation Guide

onevcat edited this page Jul 26, 2021 · 25 revisions

Everything has a beginning. For using a framework, it's installation.

Installation

Swift Package Manager

  1. Select File > Swift Packages > Add Package Dependency. Enter https://github.com/onevcat/Kingfisher.git in the "Choose Package Repository" dialog.
  2. In the next page, specify the version resolving rule as "Up to Next Major" with "7.0.0" as its earliest version.
  3. After Xcode checking out the source and resolving the version, you can choose the "Kingfisher" library and add it to your app target.

If you encounter any problem or have a question on adding the package to an Xcode project, I suggest reading the Adding Package Dependencies to Your App guide article from Apple.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate Kingfisher into your Xcode project using CocoaPods, specify it to a target in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '12.0'
use_frameworks!

target 'MyApp' do
  # your other pod
  # ...
  pod 'Kingfisher', '~> 7.0'
end

Then, run the following command:

$ pod install

You should open the {Project}.xcworkspace instead of the {Project}.xcodeproj after you installed anything from CocoaPods.

For more information about how to use CocoaPods, I suggest this tutorial.

Carthage

Carthage is a decentralized dependency manager for Cocoa application. To install the carthage tool, you can use Homebrew.

$ brew update
$ brew install carthage

To integrate Kingfisher into your Xcode project using Carthage, specify it in your Cartfile:

github "onevcat/Kingfisher" ~> 7.0

Then, run the following command to build the Kingfisher framework:

$ carthage update Kingfisher --platform iOS
# Or `--platform macOS`, `--platform tvOS`, `--platform watchOS`

At last, you need to set up your Xcode project manually to add the Kingfisher framework:

  1. On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

  2. On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script with the following content:

/usr/local/bin/carthage copy-frameworks
  1. Add the paths to the frameworks you want to use under “Input Files”:
$(SRCROOT)/Carthage/Build/iOS/Kingfisher.framework
  1. Add the paths to the copied frameworks to the “Output Files”:
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Kingfisher.framework

Manually

It is not recommended to install the framework manually, but if you prefer not to use either of the aforementioned dependency managers, you can integrate Kingfisher into your project manually. A regular way to use Kingfisher in your project would be using the Embedded Framework.

  • Add Kingfisher as a submodule. In your favorite terminal, cd into your top-level project directory, and entering the following command:
$ git submodule add https://github.com/onevcat/Kingfisher.git
  • The master branch of Kingfisher project is under active development and it may break time to time. So I suggest always use a tagged version whenever possible. Remember to replace the version number to the one you want to use.
cd Kingfisher && git checkout 7.0.0
  • Open the Kingfisher folder in Finder, and drag Kingfisher.xcodeproj into the file navigator of your app project, under your app project in Xcode.
  • In Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the "Targets" heading in the sidebar.
  • In the tab bar at the top of that window, open the "Build Phases" panel.
  • Expand the "Target Dependencies" group, and add Kingfisher.framework.
  • Click on the + button at the top left of "Build Phases" panel and select "New Copy Files Phase". Rename this new phase to "Copy Frameworks", set the "Destination" to "Frameworks", and add Kingfisher.framework of the platform you need.

Next

After installation, you could import Kingfisher to your project by adding this:

import Kingfisher

to the files in which you want to use Kingfisher.

Once you prepared, continue to have a look at the Cheat Sheet to see how to use Kingfisher.