Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/developeracademy-postech/2024-nc2-m2-widgetkit

Apple Developer Academy 3rd Morning Session NC2 Pair2(Soy&Sora - SOSO)'s WidgetKit
https://github.com/developeracademy-postech/2024-nc2-m2-widgetkit

Last synced: about 1 month ago
JSON representation

Apple Developer Academy 3rd Morning Session NC2 Pair2(Soy&Sora - SOSO)'s WidgetKit

Awesome Lists containing this project

README

        

# 2024-NC2-M2-WidgetKit
Apple Developer Academy 3rd Morning Session NC2 Pair2(Soy&Sora - SOSO)'s WidgetKit

## ๐ŸŽฅ Youtube Link
(์ถ”ํ›„ ๋งŒ๋“ค์–ด์ง„ ์œ ํŠœ๋ธŒ ๋งํฌ ์ถ”๊ฐ€)

## ๐Ÿ’ก About WidgetKit

> WwDC23๋ถ€ํ„ฐ WidgetKit์€ Interactivity๋ฅผ ์ง€์›, ์‚ฌ์šฉ์ž๊ฐ€ ์•ฑ์„ ์‹คํ–‰ํ•˜์ง€ ์•Š๊ณ ๋„ ์œ„์ ฏ ๋‚ด์—์„œ ์ง์ ‘ ์ž‘์—…์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ์ง€์›ํ•œ๋‹ค. 'Button', 'Link', 'AppIntent' ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ํ•ญ๋ชฉ์„ ์™„๋ฃŒ๋กœ ํ‘œ์‹œํ•˜๊ฑฐ๋‚˜ ์„ค์ •์„ ์ „ํ™˜ํ•˜๋Š” ๋“ฑ์˜ ์ž‘์—…์ด ๊ฐ€๋Šฅํ•˜๋‹ค. Interactive Widget์€ ์‚ฌ์šฉ์ž์˜ ํ–‰๋™์— ๋”ฐ๋ผ ์ฝ˜ํ…์ธ ๋ฅผ Refreshํ•  ์ˆ˜ ์žˆ์–ด Apple ๊ธฐ๊ธฐ์—์„œ ๋” ํ’๋ถ€ํ•˜๊ณ  ๋ชฐ์ž…๊ฐ ์žˆ๋Š” ๊ฒฝํ—˜์„ ์ œ๊ณตํ•œ๋‹ค.

## ๐ŸŽฏ What we focus on?
> WidgetKit์—์„œ iOS17๋ถ€ํ„ฐ ์ œ๊ณตํ•˜๋Š” interactivity๋ฅผ ํ™œ์šฉํ•ด ์•ฑ์„ ์‹คํ–‰ํ•˜์ง€ ์•Š๊ณ ๋„ ์•ฑ์˜ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.

## ๐Ÿ’ผ Use Case
> ๋งค์ผ ํ™•์ธํ•˜๋Š” ์šด์„ธ๋ฅผ HomeScreen์—์„œ ๋ฐ”๋กœ ๋ณผ ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋ฉฐ, ๋ถ€์ฐจ์ ์œผ๋กœ ์•„์ดํฐ์„ ๊พธ๋ฏธ๋Š” ๋ฐ ๋„์›€์„ ์ค€๋‹ค.

## ๐Ÿ–ผ๏ธ Prototype

- ์œ„์ ฏ ์ด๋ฏธ์ง€ (WidgetFamily: .systemSmall, .systemLarge / .systemMedium) : ์œ„์ ฏ์„ ์„ค์น˜ํ–ˆ์„ ๋•Œ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋‚˜ํƒ€๋‚˜๋Š” ํ™”๋ฉด

|
--|--|
.systemSmall | .systemMedium

- HeaderView : ์˜ค๋Š˜์˜ ์šด์„ธ๊ฐ€ ๋‚˜ํƒ€๋‚˜๋Š” View

- MainView : ์–ดํ”Œ์—์„œ ์ฒ˜์Œ์œผ๋กœ ๋‚˜ํƒ€๋‚˜๋Š” View

- Widget์ด ์ ์šฉ๋œ HomeScreen

## ๐Ÿ› ๏ธ About Code
```
struct ToggleFortuneIntent: AppIntent {
static var title: LocalizedStringResource = "Toggle Fortune Display"

func perform() async throws -> some IntentResult {
let defaults = UserDefaults(suiteName: "group.com")
let isShowingFortune = defaults?.bool(forKey: "isShowingFortune") ?? true
defaults?.set(!isShowingFortune, forKey: "isShowingFortune")
WidgetCenter.shared.reloadTimelines(ofKind: "TodayFortune")

return .result()
}
}
```
```
Button(intent: ToggleFortuneIntent()){
if !entry.isShowingFortune { ... } else { ... }
}
```
Interactivity๋ฅผ ์ถ”๊ฐ€ํ•˜๊ธฐ ์œ„ํ•ด์„  AppIntent๊ฐ€ ํ•„์š”ํ•จ.
AppIntent๋Š” iOS๊ฐ€ ํ•„์š”ํ•  ๋•Œ, ์˜ˆ๋ฅผ ๋“ค์–ด ์‚ฌ์šฉ์ž๊ฐ€ ์œ„์ ฏ ๋ฒ„ํŠผ๊ณผ ์ƒํ˜ธ์ž‘์šฉํ•  ๋•Œ App ์ž‘์—…์„ ์‹œ์Šคํ…œ์— ๋…ธ์ถœํ•˜๋Š” ์—ญํ• ์„ ์ˆ˜ํ–‰.
ํ•ด๋‹น ์ฝ”๋“œ์—์„œ๋Š” UserDefaults์— ์ €์žฅ๋œ "isShowingFortune" ๊ฐ’์„ ๋ถˆ๋Ÿฌ์˜ค๋„๋ก ํ•˜๊ณ , "isShowingFortune"์˜ ๊ฐ’์— ๋”ฐ๋ผ Widget์—์„œ ์˜ค๋Š˜์˜ ์šด์„ธ ๋˜๋Š” ๋ ์— ํ•ด๋‹นํ•˜๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋ณด์ด๋„๋ก ํ•จ

## ๐Ÿ‘ฉโ€๐Ÿ’ป Contributor
image |
--|--|
Soy|Sora