xcrun 使用说明
Dec 03, 2020
xcrun 是 Xcode 的工具链的一部分,一般用来配置编译环境,在跨平台的编译配置上非常有用。 内置的帮助说明非常简洁: Usage: xcrun [options] <tool name> ... arguments ... Find and execute the named command line tool from the active developer directory. The active developer directory can be set using `xcode-select`, or via the DEVELOPER_DIR environment variable. See the xcrun and xcode-select manual pages for more information. Options: -h, --help show this help message and exit --version show the xcrun version -v, --verbose show verbose logging output --sdk <sdk name> find the tool for the given SDK name --toolchain <name> find the tool for the given toolchain -l, --log show commands to be executed (with --run) -f, --find only find and print the tool path -r, --run find and execute the tool (the default behavior) -n, --no-cache do not use the lookup cache -k, --kill-cache invalidate all existing cache entries --show-sdk-path show selected SDK install path --show-sdk-version show selected SDK version --show-sdk-build-version show selected SDK build version --show-sdk-platform-path show selected SDK platform path --show-sdk-platform-version show selected SDK platform version 自动配置 sysroot 编译的时候需要指定 -sysroot=/root/path/to/sdk,include 和 lib 就基于 sysroot 指定的目录里进行查找,如果是在 macOS 上编译 iOS 程序,sysroot 就指向 iOS sdk 的目录。 …
macOS 上开启 VIM 的语法高亮功能
Nov 16, 2020
macOS 自带的 VIM 默认情况下是没有语法高亮的,编辑文件的时候白茫茫一片,体验非常不好。 手动开启语法高亮,打开终端 Terminal.app: vim ~/.vimrc 加入以下内容: syntax on 保存,再打开 VIM 就有语法高亮了。 …
恢复 Xcode 默认设置
Oct 15, 2020
一条命令就可以恢复 Xcode 的默认设置: defaults delete com.apple.dt.Xcode
Swift 里的 dispatch_once 替代方案
Sep 27, 2020
ObjC 里的 dispatch_once 使用起来很方便,但是 Swift 里废弃使用这个方法了,原因是鼓励大家使用 static let 。 …
拉取 Github 上的 Pull Request 代码到本地分支
Sep 19, 2020
如果在 GitHub 上看到一个好的 PR,作者又没有 Merge ,这个时候比较好的办法是合并到自己的 Fork 里。 …
创建 Visual Studio C++ 离线安装包
Sep 15, 2020
Visual Studio 2015 之后,微软就不再提供 Visual Studio 的 iSO 镜像下载了,而是提供按需下载的模式,如果需要在团队内部分发安装,就需要自己制作离线安装包。 如果你只需要 C++ 的推荐组件和可选组件,语言是简体中文: …
Swift 的逃逸闭包和非逃逸闭包
Aug 30, 2020
Swift 里的闭包(Closure)对应 ObjC 里的代码块(Block)。 众所周知,在闭包里引用外部变量其引用数会递增,但如果是在闭包所在的方法内部立即就执行的,引用数递增是没有必要的。 …
*** -[UIKeyboardLayoutStar release]: message sent to deallocated instance
Aug 29, 2020
项目里使用了 Swizzlling Method 黑魔法来防止 NSArray 越界之类的崩溃。 App 在使用键盘时切换到后台,就会触发一个非法访问的崩溃: *** -[UIKeyboardLayoutStar release]: message sent to deallocated instance ... 去掉黑魔法造成的风险太大了。 解决方法是禁用黑魔法的 ARC,添加编译标志 -fno-objc-arc。 …
NS_ASSUME_NONNULL_BEGIN & NS_ASSUME_NONNULL_END
Aug 29, 2020
ObjC 里一切都是对象指针,对象之前传值是传指针引用。 Swift 里一切都是对象,参数传递分为值引用和对象引用。 在 ObjC 的方法里,可以判断传进来的指针是否为 nil: - (void)foo:(id)obj { if (!obj) { return; } } 在 Swift 的方法里,只有 Optional (? & !) 才能判断是否为 nil: …
pmset 合盖省电设置
Aug 27, 2020
查看当前的电源管理设置: pmset -g 电源管理模式设置: -a: 所有模式生效 -b: 电池供电生效 -c: 使用接头外接供电生效 -u: UPS 供电生效 hibernatemode 休眠模式 0: 数据仅保持在内存里,唤醒时从内存恢复数据,断电时会丢失数据 …