1

我正在开发一个 Swift 2 项目,其中包括许多可以工作的 CocoaPod,并且由于作者没有创建 Podfile,因此我正在努力从 GitHub为这个OrderedDictionary类创建一个 podspec 文件。我跑了:

pod spec create "OrderedDictionary|https://github.com/lukaskubanek/OrderedDictionary"

OrderedDictionary.podspec在我的项目目录的根目录中创建:

#
#  Be sure to run `pod spec lint OrderedDictionary.podspec' to ensure this is a
#  valid spec and to remove all comments including this before submitting the spec.
#
#  To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
#  To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |s|

  # ―――  Spec Metadata  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  These will help people to find your library, and whilst it
  #  can feel like a chore to fill in it's definitely to your advantage. The
  #  summary should be tweet-length, and the description more in depth.
  #

  s.name         = "OrderedDictionary"
  s.version      = "0.5"
  s.summary      = "An implementation of OrderedDictionary in Swift"

  # This description is used to generate tags and improve search results.
  #   * Think: What does it do? Why did you write it? What is the focus?
  #   * Try to keep it short, snappy and to the point.
  #   * Write the description between the DESC delimiters below.
  #   * Finally, don't worry about the indent, CocoaPods strips it!
  s.description  = "This is a lightweight implementation of an ordered dictionary data structure in Swift packed into a µframework."

  s.homepage     = "https://github.com/lukaskubanek/OrderedDictionary"
  # s.screenshots  = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"


  # ―――  Spec License  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Licensing your code is important. See http://choosealicense.com for more info.
  #  CocoaPods will detect a license file if there is a named LICENSE*
  #  Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
  #

  s.license      = "MIT"
  # s.license      = { :type => "MIT", :file => "LICENSE.md" }


  # ――― Author Metadata  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the authors of the library, with email addresses. Email addresses
  #  of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
  #  accepts just a name if you'd rather not provide an email address.
  #
  #  Specify a social_media_url where others can refer to, for example a twitter
  #  profile URL.
  #

  s.author             = { "Lukas Kubanek" => "lukas.kubanek@me.com" }
  # Or just: s.author    = "Lukas Kubanek"
  # s.authors            = { "Lukas Kubanek" => "lukas.kubanek@me.com" }
  # s.social_media_url   = "http://twitter.com/Lukas Kubanek"

  # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If this Pod runs only on iOS or OS X, then specify the platform and
  #  the deployment target. You can optionally include the target after the platform.
  #

  # s.platform     = :ios
  s.platform     = :ios, "8.0"

  #  When using multiple platforms
  s.ios.deployment_target = "8.0"
  # s.osx.deployment_target = "10.7"
  # s.watchos.deployment_target = "2.0"
  # s.tvos.deployment_target = "9.0"


  # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the location from where the source should be retrieved.
  #  Supports git, hg, bzr, svn and HTTP.
  #

  s.source       = { :git => "https://github.com/lukaskubanek/OrderedDictionary.git", :tag => "v0.5" }


  # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  CocoaPods is smart about how it includes source code. For source files
  #  giving a folder will include any swift, h, m, mm, c & cpp files.
  #  For header files it will include any header in the folder.
  #  Not including the public_header_files will make all headers public.
  #

  s.source_files  = "Sources"
#s.exclude_files = "Classes/Exclude"

  # s.public_header_files = "Classes/**/*.h"


  # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  A list of resources included with the Pod. These are copied into the
  #  target bundle with a build phase script. Anything else will be cleaned.
  #  You can preserve files from being cleaned, please don't preserve
  #  non-essential files like tests, examples and documentation.
  #

  # s.resource  = "icon.png"
  # s.resources = "Resources/*.png"

  # s.preserve_paths = "FilesToSave", "MoreFilesToSave"


  # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Link your library with frameworks, or libraries. Libraries do not include
  #  the lib prefix of their name.
  #

  # s.framework  = "SomeFramework"
  # s.frameworks = "SomeFramework", "AnotherFramework"

  # s.library   = "iconv"
  # s.libraries = "iconv", "xml2"


  # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If your library depends on compiler flags you can set them in the xcconfig hash
  #  where they will only apply to your library. If you depend on other Podspecs
  #  you can include multiple dependencies to ensure it works.

  # s.requires_arc = true

  # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
  # s.dependency "JSONKit", "~> 1.4"

end

在我的 Podfile 旁边:

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

pod 'OrderedDictionary', :podspec => "OrderedDictionary.podspec"

我跑了:

pod cache clean OrderedDictionary && pod install

它在项目下创建了一个Pods/OrderedDictionaryPods

不幸的是,该组是空的,因此该项目无法在以下位置构建:

import OrderedDictionary

error: No such module 'OrderedDictionary'

棉绒通过:

pod spec lint OrderedDictionary.podspec --verbose

对于我的一生,我无法获取OrderedDictionary.swiftOrderedDictionary.h复制到项目中的 pod 组中。

奇怪的是,我确实看到OrderedDictionary.h过一次出现在小组中,但不能让它再次发生。我担心 CocoaPods 可能不是幂等的,但可能会忽略一些明显的东西。感谢您的任何帮助,您可以提供。

Xcode 7.2.1 (7C1002)、OS X 10.10.5 (14F27)、CocoaPods 0.39.0

4

1 回答 1

2

根据IvanRublev 的评论回答我自己的问题。我在这个IceCreamShop CocoaPods swift 示例中尝试了我的 podspec ,然后在它在那里工作之后,它在我的原始项目中工作。

复制步骤:

昨晚写完这个问题后,我硬着头皮下载了OrderedDictionary GitHub项目的zip,展开到我的项目目录的根目录,把我的podspec移到里面,把我的Podfile改成这样:

pod 'OrderedDictionary', :path => "OrderedDictionary"

这让我可以将它用作开发 pod,并且我看到 OrderedDictionary.swift 和 OrderedDictionary.h 被复制到了 pod 的组中。

今天在我让 IceCreamShop 工作后,我从项目目录中删除了 OrderedDictionary 目录,将我的 podspec 移回我的项目目录的根目录,并将 Podfile 更改回:

pod 'OrderedDictionary', :podspec => "OrderedDictionary.podspec"

吊舱现在工作了,即使我没有改变任何东西。

我认为这可能是 CocoaPods 中的缓存问题,导致它由于以下原因之一而不一致:

  • 不透明,诸如子项目构建失败或进程被终止等问题会使缓存处于不一致的状态,这使我们能够通过其故障检测缓存的存在。

  • 没有正确失效,所以一旦它在我的项目目录中找到文件,它就会以某种方式记住它们并在它们被删除后能够包含它们。

  • 加载和存储的行为取决于它们在哪里执行,从而允许副作用影响未来的加载和存储。

  • 存在加载和存储不确定的时间问题,因为超时优先于事实来源。

  • 来自遥远星系的宇宙射线在缓存中稍微翻转,导致我的波浪状态崩溃到现实中,我花了几个小时追逐一个错误,而不是我从来不知道这个错误存在的那个。

我喜欢 CocoaPods 并意识到这有点扯淡,但缓存问题通常会对生产力产生不利影响,我建议所有项目都可以选择禁用缓存并让它每次都运行内部一致性检查它被使用了。

以下是一些可能帮助遇到类似问题的人的命令:

sudo rm -rf ~/Library/Caches/CocoaPods/
sudo rm -rf ~/.cocoapods/repos/master/

sudo rm -rf Pods/
pod install
于 2016-02-05T21:17:53.633 回答