问题
In CocoaPods v.0.29, the 'pod try' command was added (see http://blog.cocoapods.org/CocoaPods-0.29/). From the documentation (bold emphasis mine):
In other words the command automates the following steps:
- Checkout the source of the Pod in a temporary directory.
- Search for any project looking like a demo project using some simple heuristics.
- Install any CocoaPods dependencies if needed by the located project.
- Open the workspace/project in Xcode.
I've searched both Google and StackOverflow and have not been able to find any documentation about the specific heuristics that CocoaPods uses to locate a demo project. Is the process by which CocoaPods locates a demo project, and/or best practices for including a demo project and scheme documented anywhere? I am putting together a library which I hope to turn into a CocoaPod soon, and would like to ensure that my sample project will actually work correctly with CocoaPods.
Thank you for your time.
回答1:
I was looking for this as well and the only thing I got was the source of the pod-try plugin:
# Picks a project or workspace suitable for the demo purposes in the
# given directory.
#
# To decide the project simple heuristics are used according to the name,
# if no project is found this method raises and `Informative` otherwise
# if more than one project is found the choice is presented to the user.
#
# @param [#to_s] dir
# The path where to look for projects.
#
# @return [String] The path of the project.
#
def pick_demo_project(dir)
projs = projects_in_dir(dir)
if projs.count == 0
raise Informative, 'Unable to find any project in the source files' \
" of the Pod: `#{dir}`"
elsif projs.count == 1
projs.first
elsif (workspaces = projs.grep(/(demo|example).*\.xcworkspace$/i)).count == 1
workspaces.first
elsif (projects = projs.grep(/demo|example/i)).count == 1
projects.first
else
message = 'Which project would you like to open'
selection_array = projs.map do |p|
Pathname.new(p).relative_path_from(dir).to_s
end
index = choose_from_array(selection_array, message)
projs[index]
end
end
I don't know Ruby, but seems that it gets the list of all XCode projects/workspaces (except the Pods project and the projects that have a sister workspace) and picks:
- The only item if there's only one item found.
- The only workspace that has "demo" or "example" in filename if there's only one such item found.
- The only project that has "demo" or "example" in filename if there's only one such item found.
- Nothing, but let's you choose from all the items found.
If somebody has corrections to this - they're welcomed, as I'm no Ruby guy.
来源:https://stackoverflow.com/questions/25396075/is-the-heuristic-cocoapods-uses-for-the-pod-try-command-documented-anywhere