0%

xcode関連(かんれん)

xcode相关

  1. 设置及技巧
    1. 模拟器相册图片怎么找到
    2. xcode 选择行列模式
    3. Using same version number for multiple Xcode targets Info.plist
      1. 方法一
      2. 方法二
    4. xcode build number 自动增加
    5. xcode快捷键,复制当前行并插入
  2. 参考

设置及技巧

模拟器相册图片怎么找到

一般都在这个位置~/Library/Developer/CoreSimulator/Devices/<device UDID>/data/Media/DCIM/100APPLE
You can also get the <device UDID> from Devices window (Shift+CMD+2),这个在xcode里的快捷键可以直接找到
Where the value of <device UDID> can be determined using the command: xcrun simctl list devices.
xcrun simctl list devices | grep Booted | grep -E '\w+-\w+-\w+-\w+-\w+' -o 如果有打开的模拟器,这个命令可以直接显示

xcode 选择行列模式

Shift + Control + Up/Down Arrow
Shift + Control + Click
Option + Drag

Using same version number for multiple Xcode targets Info.plist

多个 target 后如何保持 version 和 buildnumber 一致?

方法一

Add a new custom property to your project (Editor -> Add Build Setting -> Add User Defined Setting). Let’s name it MY_VERSION and let’s give it value 1.0.1.

Now go to the Info section of every target and set the version to ${MY_VERSION}.

方法二

参考自动增加 build number 类似,把所有 targets 的 plist 位置设置好,一个个同步,比如:

# Type a script or drag a script file from your workspace to insert its path.
echo "${SRCROOT}"

INFOPLIST="${SRCROOT}/xxxx/Info.plist"
INFOPLIST_Today="${SRCROOT}/Today/Info.plist"
INFOPLIST_Widget="${SRCROOT}/soWidget/Info.plist"

buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$PRODUCT_SETTINGS_PATH")
versionNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$PRODUCT_SETTINGS_PATH")
buildNumber=$[$buildNumber + 1]
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$PRODUCT_SETTINGS_PATH"

/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_Today"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $versionNumber" "$INFOPLIST_Today"

/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_Widget"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $versionNumber" "$INFOPLIST_Widget"


xcode build number 自动增加

Build Phases 添加 Run Scripts 如下,实现 build number 自动增加:

# Type a script or drag a script file from your workspace to insert its path.
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$PRODUCT_SETTINGS_PATH")
versionNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$PRODUCT_SETTINGS_PATH")
# echo $PRODUCT_SETTINGS_PATH
# echo "$buildNumber"
# echo "$versionNumber"
buildNumber=$[$buildNumber + 1]
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$PRODUCT_SETTINGS_PATH"

xcode快捷键,复制当前行并插入

以下文字放入到 x.sh文件 中保存;

#!/bin/bash

PLB="sudo /usr/libexec/PlistBuddy"
PLIST="/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/Current/Resources/IDETextKeyBindingSet.plist"

$PLB -c "Add :'Custom Commands':'Duplicate Current Lines Down' string 'selectParagraph:, delete:, yank:, moveToBeginningOfParagraph:, yank:, moveUp:, moveToEndOfParagraph:'" "$PLIST"
$PLB -c "Add :'Custom Commands':'Delete Line' string 'selectLine:, deleteBackward:'" "$PLIST"
$PLB -c "Add :'Custom Commands':'Duplicate Lines' string 'selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:'" "$PLIST"

然后执行 sh x.sh
重启 xcode 就可以搜索按键绑定的地方就可以了。

参考

Using same version number for multiple Xcode targets Info.plist