Skip to content

Instantly share code, notes, and snippets.

@bannzai
Last active June 16, 2024 02:42
Show Gist options
  • Save bannzai/64af7166a8c36dbc15779dab93a5dde6 to your computer and use it in GitHub Desktop.
Save bannzai/64af7166a8c36dbc15779dab93a5dde6 to your computer and use it in GitHub Desktop.
struct, enumに脳死でSendableをつけるsed。Viewは除外
#!/bin/bash
TARGET_DIR=$1
echo "やるお"
for file in $(find "$TARGET_DIR" -name "*.swift"); do
# struct User: * { の場合。ただし、View適応は除く
sed -i '' -E '/struct [A-Za-z0-9_]+: [^{]*View[^{]*\{/!s/(struct [A-Za-z0-9_]+: [^{]*)\{/\1, Sendable {/g' "$file"
sed -i '' -E '/enum [A-Za-z0-9_]+: [^{]*View[^{]*\{/!s/(enum [A-Za-z0-9_]+: [^{]*)\{/\1, Sendable {/g' "$file"
# struct User { の場合
sed -i '' -E 's/(struct [A-Za-z0-9_]+) \{/\1: Sendable \{/g' "$file"
sed -i '' -E 's/(enum [A-Za-z0-9_]+) \{/\1: Sendable \{/g' "$file"
# 余分なスペースを削除
# struct User: Codable , Sendable { → struct User: Codable, Sendable
sed -i '' -E 's/struct (.+) , /struct \1, /g' "$file"
sed -i '' -E 's/enum (.+) , /enum \1, /g' "$file"
# Sendableが2つついたら統合
sed -i '' -E 's/Sendable, (.+)Sendable/\1Sendable/g' "$file"
done
echo "終わりンゴ"
@bannzai
Copy link
Author

bannzai commented Jun 15, 2024

Usage:
$ ./scripts/add_sendable.sh Focus/ # Focus は対象の.swiftファイルが入っている場所

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment