Last active
September 3, 2024 14:12
-
-
Save bannzai/64af7166a8c36dbc15779dab93a5dde6 to your computer and use it in GitHub Desktop.
struct, enumに無心でSendableをつけるsed。Viewは除外
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "終わりンゴ" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
$ ./scripts/add_sendable.sh Focus/ # Focus は対象の.swiftファイルが入っている場所