技术重塑Cocoapods使用问题收集Cocoapods

CocoaPods使用中级篇

2017-11-23  本文已影响50人  summer201704

目录

profile相关参数

1. 依赖相关的指令

pod 'JSONKit', :podspec => 'https://example.com/JSONKit.podspec'

简单应用:

target 'ZipApp' do
  pod 'SSZipArchive'
end

继承别的target的依赖库

target 'ZipApp' do
  pod 'SSZipArchive'

  target 'ZipAppTests' do
    inherit! :search_paths
    pod 'Nimble'
  end
end

继承多个target的依赖库(ShowsTests 同时有ShowsApp和)

target 'ShowsApp' do
  pod 'ShowsKit'

  # Has its own copy of ShowsKit + ShowTVAuth
  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end

  target 'ShowsTests' do
    inherit! :search_paths
    pod 'Specta'
    pod 'Expecta'
  end
end
abstract_target 'Networking' do
  pod 'AlamoFire'

  target 'Networking App 1'
  target 'Networking App 2'
end
# Note: There are no targets called "Shows" in any of this workspace's Xcode projects
abstract_target 'Shows' do
  pod 'ShowsKit'

  # The target ShowsiOS has its own copy of ShowsKit (inherited) + ShowWebAuth (added here)
  target 'ShowsiOS' do
    pod 'ShowWebAuth'
  end

  # The target ShowsTV has its own copy of ShowsKit (inherited) + ShowTVAuth (added here)
  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end

  # Our tests target has its own copy of
  # our testing frameworks, and has access
  # to ShowsKit as well because it is
  # a child of the abstract target 'Shows'

  target 'ShowsTests' do
    inherit! :search_paths
    pod 'Specta'
    pod 'Expecta'
  end
end

参数有

:complete : 全部继承父target
:none :全部不继承
:search_paths :只继承父target的searchPaths

例如:
target 'App' do
  target 'AppTests' do
    inherit! :search_paths
  end
end

2. Target配置

platform: 两个参数。一个是name, 一个是target
name属性
osx for OS X, :ios for iOS, :tvos for tvOS, or :watchos for watchOS.

target:版本

例如:

platform :ios, '4.0'
platform :ios
inhibit_all_warnings : 忽略所有库中的警告,也可以指定某一个具体库的警告。例如:
//全部忽略
platform :ios, '8.0'

inhibit_all_warnings!

source 'https://github.com/CocoaPods/Specs.git'

target 'TestPod' do

  pod 'SummerOCProjectFrame', '~> 0.0'

end

//某一个忽略
pod 'SummerOCProjectFrame', '~> 0.0', :inhibit_warnings => true

3. Source : 可以指定CocoaPods Master Repository,也可以自定义的Repository。例如:

source 'https://github.com/artsy/Specs.git'
source 'https://github.com/CocoaPods/Specs.git'

4. Hooks: 提供在初始化过程中接口

plugin:插件。描述在初始化时候使用的插件。例如:
plugin 'cocoapods-keys', :keyring => 'Eidolon'
plugin 'slather'
pre_install:在pod下载完初始化前可以通过它做逻辑处理。例如:
pre_install do |installer|
  # Do something fancy!
end
post_install:在形成project后写入本地前可以通过它做逻辑处理。比如设置target的build setting, 代码如下:
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['GCC_ENABLE_OBJC_GC'] = 'supported'
    end
  end
end

5. def name end。 如果project依赖的库很多,比如有自己开发的库,有第三方的库,可以对这些库进行分类。例如:

def myPods
pod xxx
pod xxx1
pod xxx2
end

def thirdPods
pod yyy
pod yyy1
pod yyy2
end

target 'xxx' do
  myPods
  thirdPods
end

参考:https://guides.cocoapods.org/syntax/podfile.html#podfile

podspec相关参数

spec.vendored_libraries  = 'xxx/Classes/ThirdParty/*.{a}'
spec.resource_bundles = {
    'MapBox' => ['MapView/Map/Resources/*.png'],
   'OtherResources' => ['MapView/Map/OtherResources/*.png']
  }

spec.resources = ['Images/*.png', 'Sounds/*']
spec.preserve_path = 'IMPORTANT.txt'
spec.preserve_paths = 'Frameworks/*.framework'  
spec.exclude_files = 'Classes/**/unused.{h,m}'
 //不同的source_file
subspec 'Twitter' do |sp|
  sp.source_files = 'Classes/Twitter'
end

subspec 'Pinboard' do |sp|
  sp.source_files = 'Classes/Pinboard'
end

  Pod::Spec.new do |s|
  s.name = 'RestKit'

  //不同的dependencies
  s.subspec 'Core' do |cs|
    cs.dependency 'RestKit/ObjectMapping'
    cs.dependency 'RestKit/Network'
    cs.dependency 'RestKit/CoreData'
  end

  s.subspec 'ObjectMapping' do |os|
  end
  end

参考:https://guides.cocoapods.org/syntax/podspec.html

清除pod缓存

第一步:
pod cache list //查看看缓存
pod cache clean --all //清除缓存 

如果还不行,就执行下面的代码:
rm ~/Library/Caches/CocoaPods/search_index.json;
pod sutup
上一篇下一篇

猜你喜欢

热点阅读