【Swift】端末で設定されている週の始まりの曜日を取得する

# はじめに
設定→一般→言語と地域に進むと「週の始まりの曜日」を設定できます。

![スクリーンショット 2024-02-11 21.43.33.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/3ea37cbe-7a0e-5688-27ee-aa357f44abcb.png)

カレンダー使用するアプリは、この設定によってバグが生まれる可能性があるので注意が必要です。

# 取得方法
```swift
import SwiftUI

struct ContentView: View {
    @State var firstDayOfWeek = Locale.current.firstDayOfWeek
    
    var body: some View {
        Text(firstDayOfWeek.rawValue)
    }
}
```

# 試してみる
### 日曜日に設定
|||
|-|-|
|![Simulator Screenshot - iPhone 15 Pro - 2024-02-11 at 21.49.11.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/dde7a705-e09f-628e-1eec-74c963c4ca4a.png)|![Simulator Screenshot - iPhone 15 Pro - 2024-02-11 at 21.49.19.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/fcf70ff0-09f3-f80f-d3eb-832a6b3f02a5.png)|

### 月曜日に設定
|||
|-|-|
|![Simulator Screenshot - iPhone 15 Pro - 2024-02-11 at 21.50.23.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/bf3f2301-bf3e-4f23-fa30-7600a073ffd0.png)|![simulator_screenshot_08E15947-2720-488A-AC8A-E6CF5A6CEB26.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/52b2ad53-7704-1647-2e7f-8345ab214999.png)|

### 火曜日に設定
|||
|-|-|
|![simulator_screenshot_E3C8CAE7-8535-46F5-A9F8-E57B92F1D976.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/a96bc621-c835-3129-0196-8cc16ab618cc.png)|![Simulator Screenshot - iPhone 15 Pro - 2024-02-11 at 21.53.21.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/8d7d406a-feff-679d-8b6d-7b7fddb72b3e.png)|

### 水曜日に設定
|||
|-|-|
|![simulator_screenshot_94352691-6ED9-4909-B958-803FFCAE9CA1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/b6f9e2b9-0b65-d0b6-df92-1beee6f22087.png)|![simulator_screenshot_E973E3E7-C8A7-4A56-B8C9-ED65616F4FDA.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/d22d90c5-6fac-5b2a-f60a-9e81bec95bcb.png)|

### 木曜日に設定
|||
|-|-|
|![simulator_screenshot_9BA749E4-6B59-43DA-826A-F8FF1051A470.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/1427f700-f606-0c74-74e5-ffb9a7a9b42a.png)|![simulator_screenshot_51667E58-5BB2-4B92-BE68-518FEC593223.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/50eff0ab-23da-46e8-949c-d42ce65711de.png)|

### 金曜日に設定
|||
|-|-|
|![simulator_screenshot_BD49A52B-998F-41A0-8BBB-AEE440D9A0C5.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/7d2878c9-fe61-17a8-7d5d-f9bab546a259.png)|![simulator_screenshot_C9895FED-C12D-4A78-948D-0F0510CF57B8.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/6bc93b13-43b4-b6a9-eca1-e2979842efab.png)|

### 土曜日に設定
|||
|-|-|
|![simulator_screenshot_48C06AD8-AE4B-497C-A658-A46E3CB4854B.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/71050827-b54b-5b17-a458-d56e84ebe7f2.png)|![simulator_screenshot_781931A4-4828-4750-8004-E46766258E27.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/62978194-814d-fc05-ab95-368a65db2dd1.png)|

# おわり
意外と気づきにくい箇所だと思うので、カレンダーをいじる時は意識したいですね

# 公式ドキュメント
https://developer.apple.com/documentation/foundation/locale/components/3952286-firstdayofweek