在 iOS 中使用 icofont 字体
Apr 30, 2019
获取 icofont 可以在 icofont.com 下载到 icofont.ttf,里面包含了很多图标。 把下载回来的 icofont.ttf 拖到项目里,或者新建一个 fonts.bundle 用来放字体资源。 在 APP 启动的时候注册字体,注册之后就能在 APP 里全局使用了,使用方法和使用系统字体一样。 …
在 ObjC 项目里使用 Swift 静态库
Mar 29, 2019
Xcode 9 开始 Swift 支持编译生成静态类型的 framework 如果给之前的 ObjC 项目直接添加 Swift 写的 framework,在编译的时候会报错,错误信息是无法找到 Swift 的方法。 解决方法很简单,在 ObjC 项目里添加一个空的 swift 源文件就行了。 …
git with GPG sign
Mar 25, 2019
Setup GPG pub key for git server Install GPG Suite or gpgosx on macOS Create a GPG key Setup GPG pub key for github or gitlab etc. Setup GPG key for git client List all GPG key gpg -K Setup signingkey for git git config user.signingkey your-key Enable gpgsign for git commit git config commit.gpgsign true using gpg2 git config --global gpg.program $(which gpg2)
GNU auto tools
Mar 25, 2019
The GNU Autotools: Autoconf Automake Libtool (Xcode built-in) Gettext
Make carthage portable
Mar 23, 2019
I wanna run carthage without install CarthageKit.framework to system library. Download latest release get latest carthage pkg form https://github.com/Carthage/Carthage/releases Extract pkg file pkgutil --expand-full Carthage.pkg Carthage Copy to system path cp Carthage/CarthageApp.pkg/Payload/usr/local/bin/carthage /usr/local/bin mkdir -p /usr/local/Library/Frameworks cp -r Carthage/CarthageApp.pkg/Payload/Library/Frameworks/CarthageKit.framework /usr/local/Library/Frameworks Add rpath for carthage install_name_tool -add_rpath @executable_path/../Library/Frameworks /usr/local/bin/carthage install_name_tool -add_rpath @executable_path/../Library/Frameworks/CarthageKit.framework/Versions/Current/Frameworks /usr/local/bin/carthage All done. I using a shell script make it easy #!/bin/bash set -e if [ ! -f Carthage.pkg ]; then echo Carthage.pkg not found. exit -1 fi if [ -d Carthage ]; then echo found Carthage, removed rm -rf Carthage fi pkgutil --expand-full Carthage.pkg Carthage mkdir -p Carthage_portable/bin mkdir -p Carthage_portable/Library/Frameworks cp Carthage/CarthageApp.pkg/Payload/usr/local/bin/carthage Carthage_portable/bin cp -r Carthage/CarthageApp.pkg/Payload/Library/Frameworks/CarthageKit.framework Carthage_portable/Library/Frameworks rm -rf Carthage install_name_tool -add_rpath @executable_path/../Library/Frameworks Carthage_portable/bin/carthage install_name_tool -add_rpath @executable_path/../Library/Frameworks/CarthageKit.framework/Versions/Current/Frameworks Carthage_portable/bin/carthage echo Make Carthage portable at Carthage_portable echo Testing Carthage_portable/bin/carthage version Carthage_portable/bin/carthage version
fatal: cannot run gpg: No such file or directory
Mar 22, 2019
After installed GPG Site: https://gpgtools.org/ Git commit with error: fatal: cannot run gpg: No such file or directory error: gpg failed to sign the data fatal: failed to write commit object Solution: git config --global gpg.program $(which gpg) About Signing commits
Using xcrun
Mar 22, 2019
Run a command with special toolchain # using clang of toolchain org.llvm.8.0.0 xcrun --toolchain org.llvm.8.0.0 clang -v output clang version 8.0.0 Target: x86_64-apple-darwin18.2.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/LLVM8.0.0.xctoolchain/usr/bin Show SDK path xcrun --show-sdk-path --sdk iphoneos /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk xcrun --show-sdk-path --sdk iphonesimulator /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.1.sdk xcrun --show-sdk-path --sdk macosx /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
build LLVM 8 on macOS
Mar 21, 2019
TL;DR download my pre-built: LLVM8.0.1.xctoolchain.7z MD5: 32241cb3e093b15c58bd40200dc2fd76 LLVM8.0.0.xctoolchain.7z MD5: 169fd4d3fdffa5a136cbe77aac759cdc prepare building lldb Install editline Install pcre && swig Read code-signing.txt building clone llvm-project checkout 8.0 branch cd llvm run build-llvm.sh build-llvm.sh #!/bin/bash set -e mkdir build && cd build output=/tmp/llvm-build cmake -DCMAKE_INSTALL_PREFIX=${output} \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_INCLUDE_TESTS=OFF \ -DLLVM_INCLUDE_EXAMPLES=OFF \ -DLLDB_CODESIGN_IDENTITY='' \ -DLLDB_BUILD_FRAMEWORK=ON \ -DLLVM_ENABLE_PROJECTS="all" \ -DLLVM_CREATE_XCODE_TOOLCHAIN=ON \ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9 \ -GNinja \ .. ninja ninja install-xcode-toolchain echo build finish. echo toolchain installed at ${output} Note: you need install cmake and ninja first. …
A simple Dispatch Queue Pool
Mar 18, 2019
I named it MDispatchQueuePool. Really easy to use: [MDispatchQueuePool.sharedPool asyncExecute:^{ // put your code here ... }]; Here is MDispatchQueuePool.m @interface MDispatchQueuePool () { dispatch_queue_t _executionQueue; dispatch_queue_t _waitingQueue; dispatch_semaphore_t _maximumQueueSemaphore; } @end @implementation MDispatchQueuePool + (instancetype)sharedPool { static MDispatchQueuePool *pool = nil; static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ pool = [[self alloc] init]; }); return pool; } - (instancetype)init { if (self = [super init]) { _executionQueue = dispatch_queue_create("queue.exec.MDispatchQueuePool", DISPATCH_QUEUE_CONCURRENT); _waitingQueue = dispatch_queue_create("queue.wait.MDispatchQueuePool", DISPATCH_QUEUE_SERIAL); dispatch_set_target_queue(_executionQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)); dispatch_set_target_queue(_waitingQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)); NSUInteger processorCount = MAX(NSProcessInfo.processInfo.processorCount, 2); _maximumQueueSemaphore = dispatch_semaphore_create(processorCount); } return self; } - (void)asyncExecute:(dispatch_block_t)block { if (!block) { return; } dispatch_block_t blockCopy = [block copy]; dispatch_async(_waitingQueue, ^{ dispatch_semaphore_wait(self->_maximumQueueSemaphore, DISPATCH_TIME_FOREVER); dispatch_async(self->_executionQueue, ^ { blockCopy(); dispatch_semaphore_signal(self->_maximumQueueSemaphore); }); }); } @end
Build LLVM for macOS
Mar 13, 2019
Build LLVM We build a toolchain for Xcode, and include these projects: clang clang-tools-extra libcxx libcxxabi compiler-rt libunwind polly lld clone llvm project, and build the 7.0.1 version git clone https://github.com/llvm/llvm-project.git llvm-project cd llvm-project/llvm git checkout llvmorg-7.0.1 mkdir build && cd build && build_llvm.sh Build obfuscator-LLVM obfuscator-LLVM upon LLVM, so We must clone LLVM project first. We build heroims’ fork, because his fork is newer. cd llvm-project git clone https://github.com/heroims/obfuscator.git obfuscator cd obfuscator git checkout llvm-7.0 mkdir build && cd build && build_llvm.sh build_llvm.sh #!/bin/bash set -e # projects: clang; clang-tools-extra; libcxx; libcxxabi; libunwind; lldb; compiler-rt; lld; polly; debuginfo-tests output=/tmp/llvm-build cmake -DCMAKE_INSTALL_PREFIX=${output} \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_INCLUDE_TESTS=Off \ -DLLVM_INCLUDE_EXAMPLES=Off \ -DLLVM_ENABLE_LIBCXX=ON \ -DLLVM_ENABLE_CXX1Y=ON \ -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;libcxx;libcxxabi;compiler-rt;libunwind;polly;lld" \ -DLLVM_CREATE_XCODE_TOOLCHAIN=ON \ .. make -j `sysctl -n hw.logicalcpu_max` make install-xcode-toolchain echo build finish. echo toolchain installed at ${output} Download You can use my build here: …