Swift
Swift-format
installation
Homebrew
brew install swift-format
Build from source
This is useful when you want to specify swift version.
# using swift 5.5 version
git clone -b swift-5.5-branch https://github.com/apple/swift-format.git
cd swift-format
swift build
# find build product
find . -type f -name swift-format
#ex) ./swift-format/.build/x86_64-apple-macosx/debug/swift-format
Add directory including swift-format binary to .zshrc
.
source ~/.zshrc
# check if swift-format is in your path
swift-format --version
cf. https://medium.com/just-tech-it-now/swift-format-2c6786a15a4d
Configuration
Example
In root directory of project:
% swift-format -m dump-configuration > .swift-format.json
% code .swift-format.json
configure indentation in .swift-format.json:
...
"indentation" : {
- "spaces" : 2
+ "spaces" : 4
},
...
Visual Studio Code
デバッグ実行事始め
最近、AsyncStreamのbufferingNewest
をSwiftファイルに書いて動作を確認しようとしたときに、予想していなかった挙動になった。
そこで、SwiftをVisual studio codeでデバッグ実行するべく調べた。
に手順は書いてある。
ざっくり
- プロジェクトを作成
- launch.jsonにデバッグ実行用の設定を追加
- play buttonでデバッグ実行
という流れのようだ。
⌘ Shift P
でプロジェクトを作ると、デフォルトで launch.jsonにタスクの設定がなされている。
これらのタスクは、⌘ Shift B
で呼び出すことが出来る。
ここまで設定できていれば、⌘ Shift D
からデバッグ実行を開始できる。
Concurrency
swift-evolution
Swift6に向けて、どのようにConcurrencyの安全性を担保するコンパイラのチェックを導入していくかの展望が書かれている。今からどのような対応をすべきか検討する材料として参考になる。
Github apple/swift
iOS13へのバックポートの導入のPR。
その他
Sendable
Swift Package Manager
Generate Xcode project
swift package generate-xcodeproj
can generate xcodeproj file , but recent xcode(s) are enable to open Swift packages directory.
% swift package generate-xcodeproj
warning: Xcode can open and build Swift Packages directly. 'generate-xcodeproj' is no longer needed and will be deprecated soon.
generated: Some/Swift/Package/SPM.xcodeproj
(tested in Swift 5.5.1, Xcode13.1)
Actors
Swift 5.6
Scripting
Mark as deprecated
@available(*, deprecated, message: "some message")
func someDeprecatedFunc() { }
// someDeprecatedFunc()の呼び出し元にはワーニングが表示される
Property wrapper
Swift Regix
iOS16から、Swiftの言語組み込みの正規表現のAPIが使えるようになった。
iOS15以前
iOS11から、NSTextCheckingResultにrange(withName:)が追加され、名前付きキャプチャが可能になった。
Lense
Calender
Swift Build