<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:
- It uses the local files on your machine for the pod,instead of fetching them from a remote repository.
- 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 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
- Categories
- RWPickFlavor.h
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:
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
Sign uporLoginto your GitHub account.
+(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. |