https://github.com/developeracademy-postech/2024-nc2-a8-corespotlight
https://github.com/developeracademy-postech/2024-nc2-a8-corespotlight
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/developeracademy-postech/2024-nc2-a8-corespotlight
- Owner: DeveloperAcademy-POSTECH
- Created: 2024-06-17T05:45:27.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-06-20T19:33:39.000Z (8 months ago)
- Last Synced: 2024-11-17T06:16:33.383Z (3 months ago)
- Language: Swift
- Size: 127 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 2024-NC2-A8-CoreSpotlight
## ๐ฅ Youtube Link
(์ถํ ๋ง๋ค์ด์ง ์ ํ๋ธ ๋งํฌ ์ถ๊ฐ)## ๐ก About Core Spotlight
***์ฑ์ ์ด์ง ์๊ณ ๋ ์์ธ๋ ์ ๋ณด๋ฅผ ๋น ๋ฅด๊ฒ ํ์ธํ๊ณ ์ ๊ทผํ ์ ์๋ ๊ธฐ์ ***
> **Indexing**
Core Spotlight๋ฅผ ํ์ฉํ์ฌ, ์ฌ์ฉ์๊ฐ ์์ฑํ ์ ๋ณด๋ฅผ ์์ธ์ํฌ ์ ์๋ค. ์ฌ์ฉ์๋ ์ด๋ฅผ ํ์ฉํ์ฌ ์ฑ์ ์ด์ง ์๊ณ ๋ ํ์ํ ์ ๋ณด์ ๋น ๋ฅด๊ฒ ์ ๊ทผํ ์ ์๋ค.> **์ฑ ๋จ์ถ์ด**
App Intents๋ฅผ ์ฌ์ฉํ์ฌ, ์ฌ์ฉ์๋ ์ฑ์ ์ด์ง ์๊ณ ๋ ์ฑ์ ์ผ๋ถ ๊ธฐ๋ฅ์ ๋น ๋ฅด๊ฒ ์ฌ์ฉํ ์ ์๋ค.## ๐ฏ What we focus on?
> **Indexing**
์์ธ์ ํตํด ์ฌ์ฉ์๊ฐ ๊ธฐ๋กํ ์ ๋ณด์ ๋น ๋ฅด๊ฒ ์ ๊ทผํ ์ ์๋๋ก ํ๋ค.## ๐ผ Use Case
> **์ด๋์ผ์ง**
์ด๋์ผ์ง๋ฅผ ์ด ๋ค Spotlight์ ํตํด ์ฑ์ ์ด์ง ์๊ณ ๋ ์ํ๋ ๊ธฐ๋ก์ ๋น ๋ฅด๊ฒ ์ ๊ทผํ ์ ์๊ฒ ํ์!## ๐ผ๏ธ Prototype




## ๐ ๏ธ About Code
```/// Core Spotlight๋ฅผ ํตํด ๋ฐ์ดํฐ๋ฅผ ์์ธํฉ๋๋ค.
private func indexData(diary: PTDiary) {
// 1. Core Spotlight์ ์์ธ์ํฌ ์์ดํ ์ ์ ์ฅํ ๋ฐฐ์ด์ ์ ์ํฉ๋๋ค.
var searchableItems = [CSSearchableItem]()
// 2. ์ด๋ป๊ฒ ์์ธ์ํฌ์ง ์ ํฉ๋๋ค. Spotlight์ ์ง์ ์ ์ผ๋ก ๋ํ๋๋ ํญ๋ชฉ์ ๋๋ค.
let attributeSet = CSSearchableItemAttributeSet(contentType: .text) // Tip: ContentType์ ์ ํํ ์ค์ ํ๋ฉด ๊ฒ์ ์ ํ๋๊ฐ ์ฌ๋ผ๊ฐ๋๋ค!
attributeSet.title = diary.title // ์ ๋ชฉ
attributeSet.displayName = diary.title // ๋ํ๋๋ ๊ฐ(์ ๋ชฉ) cf) ios 17์์ ์์ธ ๋์์ด ์ ๋์ง ์์, ์ถ๊ฐ๋ Property ์ ๋๋ค.
attributeSet.contentDescription = diary.date.dateFormat // ๋ด์ฉ ์ค๋ช ; ์ ๋ชฉ ํ ์คํธ ๋ฐ์ ๋ํ๋ฉ๋๋ค.
attributeSet.alternateNames = diary.exercises // ๋์ฒด ํ ์คํธ; ์ค๋ช ํ ์คํธ ๋ฐ์ ๋ํ๋ฉ๋๋ค.
attributeSet.keywords = diary.exercises // ๊ฒ์ ํค์๋; ์ฌ์ฉ์๊ฐ ํด๋น ํค์๋๋ฅผ Spotlight์ ์ ๋ ฅํ๋ฉด ํด๋น ๋ฐ์ดํฐ๊ฐ ๋ํ๋ฉ๋๋ค. cf) ios 17์์ ํด๋น ๊ธฐ๋ฅ์ด ๋์ํ์ง ์์ต๋๋ค. ํ๋จ์ ๋งํฌ ์ฒจ๋ถ.
// ํค์๋๊ฐ ๋์ํ์ง ์๋ ๋ฌธ์ : https://forums.developer.apple.com/forums/thread/734996
// 3.์์ธ์ํฌ ์์ดํ ์ ์ด๊ธฐํํฉ๋๋ค.
let searchableItem = CSSearchableItem(
uniqueIdentifier: diary.id.uuidString, d
omainIdentifier: "exerciseDiary",
attributeSet: attributeSet
)
searchableItems.append(searchableItem)
// 4. ์ธ๋ฑ์ค ๋ฒ์๋ฅผ ์ ํฉ๋๋ค. cf) ๋ฏผ๊ฐ ์ ๋ณด์ธ ๊ฒฝ์ฐ default๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ๋ณดํธํ๋ ์ธ๋ฑ์ค๋ฅผ ์ฌ์ฉํฉ๋๋ค.
// let secureIndex = CSSearchableIndex(name: "์ด๋ ์ผ์ง", protectionClass:.complete)let defaultIndex = CSSearchableIndex.default() // ๊ธฐ๋ณธ ์ธ๋ฑ์ค
// 5. ์์ธ์ํฌ ์์ดํ ์ ์ธ๋ฑ์ค์ ํฌํจ์ํต๋๋ค; ์์ธ ์๋ฃ
defaultIndex.indexSearchableItems(searchableItems) { error in
if let error = error {
print("Spotlight ์์ธ ์๋: \(error.localizedDescription)")
} else {
print("Spotlight ์์ธ ์ฑ๊ณต")
}
}
}
```