<a target=_blank href="http://www.raywenderlich.com/99386/create-cocoapod-swift">点击打开链接</a><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">You’re probably familiar with some well-kNown,<a target=_blank target="_blank" href="https://github.com/CocoaPods/Specs/tree/master/Specs" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,104,55);">open-source CocoaPods</a>such as<a target=_blank target="_blank" href="https://github.com/Alamofire/Alamofire" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);">Alamofire</a>or<a target=_blank target="_blank" href="https://github.com/jdg/MBProgressHUD" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);">MBProgressHUD</a>. But sometimes you can’t find a a pod with the exact functionality you need,or you may want to separate a large project into smaller,reusable components.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">Fortunately,it’s easy to create your own CocoaPods!</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">If you’ve already created a Cocoa Touch framework for your component,you’ve already done most of the hard work. If you haven’t,don’t panic as it’s really straightforward.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">If you’ve only ever created classes as part of an iOS app,that’s okay too. You can easily create a new pod by pulling out classes and functionality that make sense for your particular use case.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">This tutorial picks up where<a target=_blank target="_blank" href="http://www.raywenderlich.com/97014" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);">How to Use CocoaPods with Swift</a>ends. If you’ve never used CocoaPods before,then that tutorial is definitely a prerequisite to this one.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">Otherwise,grab yourself a hot cup of “cocoa” (<em>sorry,Couldn’t resist!</em>) and read on! :]</p><h2 style="border: 0px; font-family: Bitter,serif; font-size: 26px; margin: -3px 0px 0px; outline: 0px; padding: 5px 0px 20px; vertical-align: baseline; color: rgb(0,55); line-height: 25.8799991607666px;">Getting Started</h2><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">Your top client is Ice Cream Shop,Inc. Their ice cream is so popular they can’t keep up with customer orders at the counter. They’ve recruited you to create a sleek iOS app that will allow customers to order ice cream right from their phone. You’ve started developing the app,and it’s coming along well.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">Download the starter project from<a target=_blank target="_blank" href="http://cdn2.raywenderlich.com/wp-content/uploads/2015/06/IceCreamShop_Final1.zip" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);">here</a>— this is the final project from<a target=_blank target="_blank" href="http://www.raywenderlich.com/97014" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);">How to Use CocoaPods with Swift</a>.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">The app has a few pod dependencies that are already included in the download,so you<em>don’t</em>need to run<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>pod install</strong></span>to install them.</p><div class="note" style="border: 1px solid black; font-family: 'Open Sans',sans-serif; font-size: 16px; margin: 5px 0px 17px; outline: 0px; vertical-align: baseline; line-height: 25.875px; padding: 14px !important; background-color: rgb(237,240,213);"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; font-family: inherit; font-size: 1em; font-style: inherit; font-weight: inherit; outline: 0px; vertical-align: baseline;"><span style="border: 0px; font-family: Helvetica,sans-serif; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>Note:</strong></span>If you worked through<a target=_blank target="_blank" href="http://www.raywenderlich.com/97014" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);">How to Use CocoaPods with Swift</a>this next section may seem familiar – it’s simply a review of that tutorial. Feel free to skip ahead as needed.</p></div><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">Open<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>IceCreamShop.xcworkspace</strong></span>and then<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>Main.storyboard</strong></span>,found in the<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>Views\Storyboards & Nibs</strong></span>group,to see how the app is laid out.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">Here’s a quick overview of the<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>Choose Your Flavor</strong></span>scene,which is the heart of the application:</p><ul style="border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; margin: 0px 0px 3px 30px; outline: 0px; padding: 0px; vertical-align: baseline; line-height: 25.8799991607666px;"><li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>PickFlavorViewController</strong></span>: handles user interaction,such as when the user selects an ice cream flavor.</li><li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>PickFlavorDataSource</strong></span>: is the data source for the collection view that displays ice cream flavors.</li><li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>IceCreamView</strong></span>: is a custom view that displays an ice cream cone and is backed by a<code style="border: 0px; font-family: 'Droid Sans Mono',sans-serif; font-size: 14px; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);">Flavor</code>model.</li><li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>ScoopCell</strong></span>: is a custom collection view cell that contains a<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>ScoopView</strong></span>,which is also backed by an instance of the<code style="border: 0px; font-family: 'Droid Sans Mono',55);">Flavor</code>model class.</li></ul><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;"><a target=_blank target="_blank" href="http://cdn2.raywenderlich.com/wp-content/uploads/2015/03/storyboard_annotated.png" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><img src="http://cdn3.raywenderlich.com/wp-content/uploads/2015/03/storyboard_annotated-427x500.png" alt="Storyboard Annotated" title="Storyboard Annotated" width="427" height="500" class="aligncenter size-large wp-image-98978" style="max-width: 650px; height: auto; vertical-align: top; border: 0px; clear: both; display: block; margin-left: auto; margin-right: auto; margin-bottom: 1.625em;" /></a></p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">The top managers at Ice Cream Shop really like how the app is coming along,but they’ve added a new requirement: ice cream retailers need to have the same choose-your-own-flavor functionality in their apps.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">Wait,that wasn’t in the original design. But that should be no probelm for a super developer like you!</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;"><a target=_blank target="_blank" href="http://cdn1.raywenderlich.com/wp-content/uploads/2014/11/SuperDev.jpg" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><img src="http://cdn1.raywenderlich.com/wp-content/uploads/2014/11/SuperDev.jpg" alt="SuperDev" width="303" height="194" class="aligncenter size-full wp-image-88162" style="max-width: 650px; height: auto; vertical-align: top; border: 0px; clear: both; display: block; margin-left: auto; margin-right: auto; margin-bottom: 1.625em;" /></a></p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">Can you guess how you’re going to do this? Yep,you’re going to pull this functionality into its own CocoaPod!</p><h2 style="border: 0px; font-family: Bitter,55); line-height: 25.8799991607666px;">Setting up Your Pod</h2><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">Create a new Xcode project and select<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>iOS\Framework & Library\Cocoa Touch Framework</strong></span>,and then click<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>Next</strong></span>:</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;"><a target=_blank target="_blank" href="http://cdn3.raywenderlich.com/wp-content/uploads/2015/03/cocoa_touch_framework.png" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><img src="http://cdn4.raywenderlich.com/wp-content/uploads/2015/03/cocoa_touch_framework-480x284.png" alt="Create Cocoa Touch Framework" title="Create Cocoa Touch Framework" width="480" height="284" class="aligncenter size-medium wp-image-100395" style="max-width: 650px; height: auto; vertical-align: top; border: 0px; clear: both; display: block; margin-left: auto; margin-right: auto; margin-bottom: 1.625em;" /></a></p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">Enter<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>RWPickFlavor</strong></span>for the product name and<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>Swift</strong></span>for the language. Click<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>Next</strong></span>.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">For the purposes of this tutorial you will create the project in<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>~/Documents/Libraries</strong></span>. Choose the<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>Documents</strong></span>folder in your home directory. If you don’t already have a<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>Libraries</strong></span>folder,click on the<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>New Folder</strong></span>button in the bottom and create it.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">Finally,choose the<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>Libraries</strong></span>folder and click<span style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(0,55);"><strong>Create</strong></span>.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">The directory where you save your development pods is important because you will need to reference this directory from your Podfile during local development.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 10px; border: 0px; font-family: 'Open Sans',sans-serif; font-size: 16px; outline: 0px; vertical-align: baseline; line-height: 25.8799991607666px;">normally,when you<em>use</em>CocoaPods,you include dependencies in your Podfile like this:</p><div class="wp_codeBox" style="border: 1px solid silver; font-family: 'Open Sans',sans-serif; font-size: 16px; margin: 0px 0px 0.5em; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(17,0); width: 782.03125px; overflow: auto; line-height: 25.8799991607666px; background-color: rgb(249,249,249);"><table class=" " style="border: 0px; font-family: inherit; font-size: 16px; font-style: inherit; font-weight: inherit; outline: 0px; padding: 0px; vertical-align: baseline; border-collapse: collapse; border-spacing: 0px; width: 782px; margin: 0px !important;"><tbody style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><tr id="p993861" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><td class="code" id="p99386code1" style="font-family: inherit; font-size: 16px; border: 0px; font-style: inherit; margin: 0px; outline: 0px; padding: 2px 4px; vertical-align: top;"><pre class="ruby" style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 12px; font-style: inherit; font-weight: inherit; outline: 0px; padding: 0px; vertical-align: baseline; width: auto; float: none; clear: none; overflow: visible; line-height: 1.333; word-wrap: break-word; white-space: pre-wrap; background: 0px 50%;">pod <span style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(153,102,0);">'PodName'</span>,<span style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(153,0);">'~> 1.0'</span>

But when you’re developingyour ownCocoaPod,you will instead specify a local path,like this:

pod 'MyPodName',:path => '~/Path/To/Folder/Containing/My/Pod'

There are two benefits to this approach:

  1. It uses the local files on your machine for the pod,instead of fetching them from a remote repository.
  2. normally,you don’t make changes to a pod included by your app because those changes would be overwritten the next time you runpod install,as the pod will be re-fetched from the remote repository and the source files you changed would be overwritten. By using the:path =>Syntax,you can easily make changes to the pod during development that won’t be overwritten,since the specified path is Now thesourceof the CocoaPod,and thus your changes won’t be lost when you runpod installagain.

While you can use a different location for your development pods,in general I recommend putting them in~/Documents/Libraries. This is also a good location if you work with a team of developers since CocoaPods kNows to expand the tilde as the user’s home directory; therefore you don’t need to hard code an absolute path in the Podfile to this directory.

You can also use other CocoaPods within your project as dependencies for the CocoaPod you created — you simply need a Podfile to manage your CocoaPod’s dependencies.

Close Xcode,then enter the following commands in Terminal:

cd ~/Documents/Libraries/RWPickFlavor
pod init
open -a Xcode Podfile

This creates a new Podfile and opens it in Xcode.

Replace the entire contents of the new Podfile with the following:

platform :ios,'8.0'
use_frameworks!

target 'RWPickFlavor' do
  pod 'Alamofire',0)">'~> 1.2'
  pod 'MBProgressHUD',0)">'~> 0.9.0'
end

This declares thatRWPickFlavorwill have external dependencies on bothAlamofireandMBProgressHUD.

Save and close the Podfile,then enter the following command in Terminal:

pod install

Just as you’d expect,this creates a workspace and installs the varIoUs requisite files.

Note: Ifpod installgives you any warnings,then you’re likely using an older version of CocoaPods. Swift based CocoaPods,such as Alamofire,require CocoaPods version 0.36.0 or newer. You can check the version of CocoaPods you have installed by running the following command in Terminal:

pod --version

If that’s the case,enter the following in Terminal to install the latest version of CocoaPods:

sudo gem install CocoaPods

Enter the following command in Terminal to open the newly createdRWPickFlavorworkspace:

open RWPickflavor.xcworkspace

Your project navigator should Now look like the following:

You Now need to copy a few of the existing files from theIceCreamShopworkspace intoRWPickFlavor.

First,create the following groups inRWPickFlavor.xcworkspaceto hold the files you’re going to copy:

  • Categories
  • Controllers
  • Factories
  • Models
  • Views
    • Ice Cream
    • Storyboards & Nibs

Now drag and drop everything —exceptforAppDelegate.swiftandLaunchScreen.xib— from the above groups inIceCreamShop.xcworkspaceinto the corresponding groups inRWPickFlavor.xcworkspacelike so:

When prompted,ensure thatCopy items if neededis checked so that each file will actually be copied instead of simply linked.

When you’re done,RWPickFlavorshould have the following files:

  • RWPickFlavor
    • RWPickFlavor.h
      • Categories
        • RGBAColorFromString.swift
      • Controllers
        • PickFlavorDataSource.swift
        • PickFlavorViewController.swift
      • Factories
          FlavorFactory.swift
      • Models
          Flavor.swift
      • Supporting Files
          Info.plist
      • Views

      • Ice Cream
        • IceCreamView.swift
        • ScoopCell.swift
        • ScoopView.swift
      • Storyboard & Nibs
        • Main.storyboard

Once you’re sure all the files have been copied over,55)">deletethe originals and any empty groups fromIceCreamShop,leaving just the files inRWPickFlavor. Take care not to delete any of the following:

  • AppDelegate.swift
  • LaunchScreen.xib
  • Images.xcassets
  • Anything under theSupporting Filesgroup

Now openInfo.plist,found under theSupporting Filesgroup,and delete the line forMain storyboard file base name.

Build and run. You shouldn’t see any errors,and you’ll eventually see the “Ice Cream Shop” logo followed by a black screen.

What About the Images?

You may have noticed that you didn’t copy over theResourcesgroup; this is because you need to copy justbackground.jpgitself into theResourcesfolder ofRWPickFlavor— not the completeImages.xcassetsfile.

Resourcesgroup within Next,selectImages.xcassetsinbackgroundand selectShow In Finder,like so:

Now drag and dropbackground.jpgfromFinderinto theResourcesgroup inRWPickFlavor. Again,make sure that you checkCopy items if neededwhen prompted. After you’ve copied the image,delete the originalbackgroundfromIceCreamShop.

Finally,inRWPickFlavorupdate the image view’s image on theChoose Your Flavorscene inMain.storyboardso that it refers tobackground.jpginstead of simplybackground:

Believe it or not,the hardest part of creating your pod is done! :]

CocoaPods and Git

Since CocoaPods is bootstrapped on top of Git,each pod will need to have its own Git repository. If you already have a preferred Git host,great — you can use it to host your repository.

If you don’t,GitHubis an excellent choice as it’s well-kNown by developers and has a free plan for open-source projects.

Bitbucketis another great option as it has a free unlimited tier,including private repositories,for teams of up to five developers.

This tutorial usesGitHub,but feel free to use your preferred Git host instead.

GitHub Repo Setup

ottom:0px; padding-top:0px; padding-bottom:10px; border:0px; font-family:'Open Sans',Sign uporLoginto your GitHub account.

ottom:0px; padding-top:0px; padding-bottom:10px; border:0px; font-family:'Open Sans',click on the+(create new) icon on the top right of the screen and selectNew repositoryas shown below:
EnterRWPickFlavorfor theRepository name,and selectCreate repository.

Github will create a new repository under your account; you’ll then see the following screen with aQuick setupsection that displays your repository URL:

You’ll need this URL in just a moment,so leave the page open for now.

Now you need a second repository to host all of your private pod specs — you’ll use this later on in the tutorial.

Opengithub.comin a new tab; again,press theCreate newicon and selectNew repository. Name this repositoryRWPodSpecs,sans-serif; font-size:16px; outline:0px; vertical-align:baseline; line-height:25.8799991607666px"> Leave this tab open as well so you can easily grab the URL later when you need it.

Podspec Setup

Now you need to create theRWPickFlavor.podspecfile forRWPickFlavor. ThePodspecincludes basic information such as the pod’s name,version and Git download URL.

Enter the following commands in Terminal,hitting enter after each one:

cd ~/Documents/Libraries/RWPickFlavor
pod spec create RWPickFlavor
open -a Xcode RWPickFlavor.podspec

This createsRWPickFlavor.podspecand opens it in Xcode.

There’s a lot of excellent documentation and examples in the default Podspec – however,you don’t need most of it.

Replace everything inRWPickFlavor.podspecwith the following:

Pod::Spec.new do |s|

  # 1
  s.platform = :ios
  s.ios.deployment_target = '8.0'
  s.name = "RWPickFlavor"
  s.summary = "RWPickFlavor lets a user select an ice cream flavor."
  s.requires_arc = true

  # 2
  s.version = "0.1.0"

  # 3
  s.license = { :type "MIT",51)">:file "LICENSE" }

  # 4 - Replace with your name and e-mail address
  s.author = { "[Your Name Goes Here]" "[Your_Email@Your_Email_Domain.com]" # For example,
  # s.author = { "Joshua Greene" => "jrg.developer@gmail.com" }


  # 5 - Replace this URL with your own Github page's URL (from the address bar)
  s.homepage = "[Your RWPickFlavor Homepage URL Goes Here]"

  # s.homepage = "https://github.com/JRG-Developer/RWPickFlavor"


  # 6 - Replace this URL with your own Git URL from "Quick Setup"
  s.source = :git "[Your RWPickFlavor Git URL Goes Here]",51)">:tag "#{s.version}"# s.source = { :git => "https://github.com/JRG-Developer/RWPickFlavor.git",:tag => "#{s.version}"}


  # 7
  s.framework = "UIKit"
  s.dependency '~> 1.1'
  s.'~> 0.9.0'

  # 8
  s.source_files = "RWPickFlavor/**/*.{swift}"

  # 9
  s.resources = "RWPickFlavor/**/*.{png,jpeg,jpg,storyboard,xib}"
 Just like a Podfile,the Podspec is written in Ruby. Be extra careful not to make any typos,or else the pod will likely fail to validate and/or install later. 

Here’s what’s going on:

  1. You first specify basic information about the pod. Swift based CocoaPodsmusthave a minimum deployment target of 8.0 or higher. If you specify a lower version,the pod won’t install correctly.
  2. A Podspec is essentially a snapshot in time of your CocoaPod as denoted by a version number. When you update a pod,you will also need to update the Podspec’s version. All CocoaPods are highly encouraged to followSemantic Versioning. If you’re not familiar with Semantic Versioning,seeHow to Use CocoaPods with Swiftfor more information.
  3. All pods must specify a license. If you don’t,CocoaPods will present a warning when you try to install the pod,and you won’t be able to upload it to CocoaPodstrunk– the master specs repo.
  4. Here you specify information about yourself,the pod author. Enter your name and e-mail address instead of the placeholder text.
  5. Here you need to specify the URL for your pod’s homepage. It’s okay to simply copy and paste the Github homepage from your browser’s address bar to use here.
  6. Replace this URL with the Git download URL from the “Quick Setup” section of the first repo you created above. In general,it’s best to use either ahttp:orhttps:URL to make it easier for other users to consume. You can use an SSH URL if you want,but you’ll need to make sure that everyone on your team — and whoever else needs access to the CocoaPod — already has their public/private key pairs setup with your Git host.
  7. Here you specify the framework and any pod dependencies.
  8. Here you specify thepublic source filesbased on file extensions; in this case,you specify.swiftas the extension.
  9. Finally,you specify theresourcesbased on their file extensions.

Like every other pod,you’ll need to create theLICENSEfile.

copy and paste the MIT License foundhereinto your favorite text editor,and then save the file asLICENSE– with no extension – in~/Documents/Libraries/RWPickFlavor. Make sure to replace[year]and[fullname]with the actual values- uh,the year and your actual name,of course. ;]

Choose a Licenseis a really great site that helps you choose the most appropriate open-source license for your project,and is built and maintained by the good folks at GitHub.

Push to Git

You’re finally ready to push theRWPickFlavorpod to its new home on GitHub!

ottom:0px; padding-top:0px; padding-bottom:10px; border:0px; font-family:'Open Sans',replacing[Your RWPickFlavor Git URL]with the Git URL forRWPickFlavorrepo you created earlier:

cd ~/Documents/Libraries/RWPickFlavor
git init
git add .
git commit -m "Initial commit"
git tag 0.1.0
git remote add origin [Your RWPickFlavor Git URL]
git push -u origin master --tags

If prompted,enter your username and password for Github.

This commits all of the files within theRWPickFlavordirectory,creates a new0.1.0tag,and pushes eveything to your remote repository.

Congratulations,you’ve just created your first CocoaPod!

You’ve created your first CocoaPod,but can you actually use it? Well,not quite yet. :]

You first need to add your Podspec to a private specs repo; this lets CocoaPods find the pod when you try to install it. Fortunately,you’ve already created a Git repo for this,so this final step is relatively straightforward.

Enter the following in Terminal,making sure you’re still in theRWPickFlavordirectory:

pod repo add RWPodSpecs [Your RWPodSpecs Git URL]
pod repo push RWPodSpecs RWPickFlavor.podspec

Make sure to replace[Your RWPodSpecs Git URL]with the Git URL forRWPodSpecsrepo you created earlier.

This creates a local reference toRWPodSpecsthat’s stored in~/.cocoapodson your machine,and pushes theRWPickFlavor.podspecto it.

You now have a private pod specs repo set up! Easier than you thought,right?

Using Your New CocoaPod

It’s finally time to use your newly created pod.

Open the Podfile forIceCreamShopand replace its contents with the following:

platform '8.0'

source 'https://github.com/CocoaPods/Specs.git'
source '[Your RWPodSpecs Git URL Goes Here]'

use_frameworks!

target 'IceCreamShop' 'RWPickFlavor',0)">'~/Documents/Libraries/RWPickFlavor'
 Make sure that you replace[Your RWPodSpecs Git URL Goes Here]with the Git URL for yourRWPodSpecsrepo. 

Then,runpod installin Terminal.

AppDelegate.swiftwith the following:

import UIKit
import RWPickFlavor

@UIApplicationMain
class AppDelegate: UIResponder,UIApplicationDelegate {

  var windowUIWindow?
  var rootViewControllerUIViewController!

  func application(applicationUIApplication,didFinishLaunchingWithOptions 
    launchOptions: [NSObject : AnyObject]?) -> Bool {

    setupRootViewController()

    window = UIWindow(frame: UIScreen.mainScreen).bounds)
    window?.rootViewController = rootViewController
    window?.makeKeyAndVisible)

    return true
  }

  func setupRootViewController{
    let bundle NSBundle(forClass: PickFlavorViewController.self)
    let storyboard = UIStoryboard(name: "Main",bundle: bundle)
    rootViewController = storyboard.instantiateInitialViewController) as! UIViewController
  }
}

InsetupRootViewController(),you get a reference to theRWPickFlavor“bundle” – which is actually a dynamic framework – create a reference to theMain.storyboard,and instantiate its root view controller.

Build and run. You’ll be greeted with the familiar “Choose Your Flavor” screen. Awesome! :]

Abstracting All The Things!

If you’re like me,you’re probably thinking,“Wow,App Delegate sure knows a lot about the structure of RWPickFlavor!”

Fortunately,there’s something you can do to reduce this tight-coupling: useBetterBaseClasses– a CocoaPod that makes creating other CocoaPods easier.

Add the following code to the pod file forRWPickFlavor,right after the line forAlamofire:

pod 'BetterBaseClasses',0)">'~> 1.0'

Likewise,add the following toRWPickFlavor.podspec,right below the line for

s. Now replace thes.versionline with the following: 
s."0.2.0"

Here you’re declaringBetterBaseClassesas a dependency,and then bumping the version of your CocoaPod.

Now runpod installin Terminal to install this new dependency.

ottom:0px; padding-top:0px; padding-bottom:10px; border:0px; font-family:'Open Sans',add the following import toPickFlavorViewController,again right after the line for

import BetterBaseClasses

Then replace the class deFinition with the following:

public class PickFlavorViewController: BaseViewController,UICollectionViewDelegate {

This changesPickFlavorViewControllerso it inherits fromBaseViewController,which is part ofBetterBaseClasses.

Now you need to push these changes to both yourRWPickFlavorandRWPodSpecsrepositories. Run the following commands in Terminal:

"Added BetterBaseClasses dependency"
git tag 0.2.0
git push origin master --tags
pod repo push RWPodSpecs RWPickFlavor.podspec

ottom:0px; padding-top:0px; padding-bottom:10px; border:0px; font-family:'Open Sans',you need to pull this change into Update the Podfile forIceCreamShopby replacing thepod 'RWPickFlavor'line with the following:

pod '~> 0.2.0'

Here you’re updating the Podfile to request the version ofRWPickFlavoryou just pushed.

Then executepod installin Terminal to update this dependency in Lastly,replace the entire contents ofAppDelegate.swiftwith the following:

UIWindow?

  {

    window UINavigationController(rootViewController: 
      PickFlavorViewController.instanceFromStoryboard))
    window?.makeKeyAndVisible That’s much simpler! 

BetterBaseClassesadds categories toUIViewController,UITableViewController,and other UIkit classes. This includes a category calledUIViewController+BetterBaseClasses,which adds convenience methods such asinstanceFromStoryboard()to make it super easy to instantiate view controllers,whether they live in the main bundle or somewhere else,such as a framework in this case.

Build and run. Once again,you should be greeted with the familiar “Choose Your Flavor” screen.

Where to Go From Here?

You can download the completed IceCreamShop projecthere,and the RWPickFlavor podhere.

You’re Now ready to start making your own CocoaPods! However,what you’ve covered in this tutorial is really just the tip of the iceberg when it comes to CocoaPods. Check out theCocoaPods Guidesto learn everything you need to kNow about creating CocoaPods.

After you create a CocoaPod,you might consider adding it to theCocoaPods Master Specs Reposo that it will be made available viaCocoaPods.orgto thousands of developers around the world. Refer to theCocoaPods Trunkblog post to find out how you can do this!

If you have any questions or comments about the tutorial,feel free to join the discussion in the comments below!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


效率成吨提升之代码生成器-蓝湖工具神器iOS,Android,Swift,Flutter
软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘贴.待开发的功能:1.支持自动生成约束2.开发设置页面3.做一个浏览器插件,支持不需要下载整个工程,可即时操作当前蓝湖浏览页面4.支持Flutter语言模板生成5.支持更多平台,如Sketch等6.支持用户自定义语言模板
【Audio音频开发】音频基础知识及PCM技术详解
现实生活中,我们听到的声音都是时间连续的,我们称为这种信号叫模拟信号。模拟信号需要进行数字化以后才能在计算机中使用。目前我们在计算机上进行音频播放都需要依赖于音频文件。那么音频文件如何生成的呢?音频文件的生成过程是将声音信息采样、量化和编码产生的数字信号的过程,我们人耳所能听到的声音频率范围为(20Hz~20KHz),因此音频文件格式的最大带宽是20KHZ。根据奈奎斯特的理论,音频文件的采样率一般在40~50KHZ之间。奈奎斯特采样定律,又称香农采样定律。...............
见过仙女蹦迪吗?一起用python做个小仙女代码蹦迪视频
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿遍又亿遍,久久不能离开!看着小仙紫姐姐的蹦迪视频,除了一键三连还能做什么?突发奇想,能不能把舞蹈视频转成代码舞呢?说干就干,今天就手把手教大家如何把跳舞视频转成代码舞,跟着仙女姐姐一起蹦起来~视频来源:【紫颜】见过仙女蹦迪吗 【千盏】一、核心功能设计总体来说,我们需要分为以下几步完成:从B站上把小姐姐的视频下载下来对视频进行截取GIF,把截取的GIF通过ASCII Animator进行ASCII字符转换把转换的字符gif根据每
自定义ava数据集及训练与测试 完整版 时空动作/行为 视频数据集制作 yolov5, deep sort, VIA MMAction, SlowFast
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至2022年4月底。我已经将这篇博客的内容写为论文,上传至arxiv:https://arxiv.org/pdf/2204.10160.pdf欢迎大家指出我论文中的问题,特别是语法与用词问题在github上,我也上传了完整的项目:https://github.com/Whiffe/Custom-ava-dataset_Custom-Spatio-Temporally-Action-Video-Dataset关于自定义ava数据集,也是后台
【视频+源码】登录鉴权的三种方式:token、jwt、session实战分享
因为我既对接过session、cookie,也对接过JWT,今年因为工作需要也对接了gtoken的2个版本,对这方面的理解还算深入。尤其是看到官方文档评论区又小伙伴表示看不懂,所以做了这期视频内容出来:视频在这里:本期内容对应B站的开源视频因为涉及的知识点比较多,视频内容比较长。如果你觉得看视频浪费时间,可以直接阅读源码:goframe v2版本集成gtokengoframe v1版本集成gtokengoframe v2版本集成jwtgoframe v2版本session登录官方调用示例文档jwt和sess
【Android App】实战项目之仿微信的私信和群聊App附源码和演示视频 超详细必看
【Android App】实战项目之仿微信的私信和群聊App(附源码和演示视频 超详细必看)
采用MATLAB对正弦信号,语音信号进行生成、采样和恢复,利用MATLAB工具箱对混杂噪声的音频信号进行滤波
采用MATLAB对正弦信号,语音信号进行生成、采样和内插恢复,利用MATLAB工具箱对混杂噪声的音频信号进行滤波
Keras深度学习实战40——音频生成
随着移动互联网、云端存储等技术的快速发展,包含丰富信息的音频数据呈现几何级速率增长。这些海量数据在为人工分析带来困难的同时,也为音频认知、创新学习研究提供了数据基础。在本节中,我们通过构建生成模型来生成音频序列文件,从而进一步加深对序列数据处理问题的了解。
  • • 效率成吨提升之代码生成器-蓝湖工具神器…
  • • 【Audio音频开发】音频基础知识及PCM技…
  • • 见过仙女蹦迪吗?一起用python做个小仙…
  • • 【Android App】实战项目之仿抖音的短视…
  • • 自定义ava数据集及训练与测试 完整版 时…
  • • 【视频+源码】登录鉴权的三种方式:tok…
  • • 【Android App】实战项目之仿微信的私信…
  • • 零基础用Android Studio实现简单的本地…
  • • 采用MATLAB对正弦信号,语音信号进行生…
  • • Keras深度学习实战40——音频生成
  • • 视频实时行为检测——基于yolov5+deeps…
  • • 数电实验 数字电子钟设计 基于quartus …
  • • 腾讯会议使用OBS虚拟摄像头
  • • 文本生成视频Make-A-Video,根据一句话…
  • • 信号处理——MATLAB音频信号加噪、滤波
  • • 【新知实验室 - TRTC 实践】音视频互动…
  • • Keras深度学习实战39——音乐音频分类
  • • C++游戏game | 井字棋游戏坤坤版配资源…

swift 创建cocoapod的更多相关文章

  1. 使用Html5多媒体实现微信语音功能

    这篇文章主要介绍了使用Html5多媒体实现微信语音功能,需要的朋友可以参考下

  2. HTML5 canvas 瀑布流文字效果的示例代码

    这篇文章主要介绍了HTML5 canvas 瀑布流文字效果的示例代码的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  3. 详解HTML5中CSS外观属性

    这篇文章主要介绍了HTML5中CSS外观属性的相关知识,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,,需要的朋友可以参考下

  4. 基于Html5 canvas实现裁剪图片和马赛克功能及又拍云上传图片 功能

    这篇文章主要介绍了基于Html5 canvas实现裁剪图片和马赛克功能及又拍云上传图片 功能,需要的朋友可以参考下

  5. html5中canvas图表实现柱状图的示例

    本篇文章主要介绍了html5中canvas图表实现柱状图的示例,本文使用canvas来实现一个图表,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  6. 有关HTML5页面在iPhoneX适配问题

    这篇文章主要介绍了有关HTML5页面在iPhoneX适配问题,需要的朋友可以参考下

  7. Html5自定义字体解决方法

    这篇文章主要介绍了Html5自定义字体解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  8. Html5 页面适配iPhoneX(就是那么简单)

    这篇文章主要介绍了Html5 页面适配iPhoneX(就是那么简单),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  9. 吃透移动端 Html5 响应式布局

    这篇文章主要介绍了吃透移动端 Html5 响应式布局,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  10. HTML5 图片悬停放大的实现代码示例

    这篇文章主要介绍了HTML5 图片悬停放大的实现代码示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

随机推荐

  1. Swift UITextField,UITextView,UISegmentedControl,UISwitch

    下面我们通过一个demo来简单的实现下这些控件的功能.首先,我们拖将这几个控件拖到storyboard,并关联上相应的属性和动作.如图:关联上属性和动作后,看看实现的代码:

  2. swift UISlider,UIStepper

    我们用两个label来显示slider和stepper的值.再用张图片来显示改变stepper值的效果.首先,这三个控件需要全局变量声明如下然后,我们对所有的控件做个简单的布局:最后,当slider的值改变时,我们用一个label来显示值的变化,同样,用另一个label来显示stepper值的变化,并改变图片的大小:实现效果如下:

  3. preferredFontForTextStyle字体设置之更改

    即:

  4. Swift没有异常处理,遇到功能性错误怎么办?

    本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请发送邮件至dio@foxmail.com举报,一经查实,本站将立刻删除。

  5. 字典实战和UIKit初探

    ios中数组和字典的应用Applicationschedule类别子项类别名称优先级数据包contactsentertainment接触UIKit学习用Swift调用CocoaTouchimportUIKitletcolors=[]varbackView=UIView(frame:CGRectMake(0.0,0.0,320.0,CGFloat(colors.count*50)))backView

  6. swift语言IOS8开发战记21 Core Data2

    上一话中我们简单地介绍了一些coredata的基本知识,这一话我们通过编程来实现coredata的使用。还记得我们在coredata中定义的那个Model么,上面这段代码会加载这个Model。定义完方法之后,我们对coredata的准备都已经完成了。最后强调一点,coredata并不是数据库,它只是一个框架,协助我们进行数据库操作,它并不关心我们把数据存到哪里。

  7. swift语言IOS8开发战记22 Core Data3

    上一话我们定义了与coredata有关的变量和方法,做足了准备工作,这一话我们来试试能不能成功。首先打开上一话中生成的Info类,在其中引用头文件的地方添加一个@objc,不然后面会报错,我也不知道为什么。

  8. swift实战小程序1天气预报

    在有一定swift基础的情况下,让我们来做一些小程序练练手,今天来试试做一个简单地天气预报。然后在btnpressed方法中依旧增加loadWeather方法.在loadWeather方法中加上信息的显示语句:运行一下看看效果,如图:虽然显示出来了,但是我们的text是可编辑状态的,在storyboard中勾选Editable,再次运行:大功告成,而且现在每次单击按钮,就会重新请求天气情况,大家也来试试吧。

  9. 【iOS学习01】swift ? and !  的学习

    如果不初始化就会报错。

  10. swift语言IOS8开发战记23 Core Data4

    接着我们需要把我们的Rest类变成一个被coredata管理的类,点开Rest类,作如下修改:关键字@NSManaged的作用是与实体中对应的属性通信,BinaryData对应的类型是NSData,CoreData没有布尔属性,只能用0和1来区分。进行如下操作,输入类名:建立好之后因为我们之前写的代码有些地方并不适用于coredata,所以编译器会报错,现在来一一解决。

返回
顶部