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

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

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
![image](https://github.com/DeveloperAcademy-POSTECH/2024-NC2-A8-CoreSpotlight/assets/74140181/bf11399f-47d8-4143-8014-064b7e0dd507)
![image](https://github.com/DeveloperAcademy-POSTECH/2024-NC2-A8-CoreSpotlight/assets/74140181/8e63db2c-8041-4dc6-8228-508cc1f56f0c)
![image](https://github.com/DeveloperAcademy-POSTECH/2024-NC2-A8-CoreSpotlight/assets/74140181/415c2694-d312-4402-a2de-b7d205d35e45)
![image](https://github.com/DeveloperAcademy-POSTECH/2024-NC2-A8-CoreSpotlight/assets/74140181/874a3fca-96f3-423e-8dd8-c71f1b49b603)
![image](https://github.com/DeveloperAcademy-POSTECH/2024-NC2-A8-CoreSpotlight/assets/74140181/a32ed42b-ff12-400f-ae7c-b938a1559efd)

## ๐Ÿ› ๏ธ 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 ์ƒ‰์ธ ์„ฑ๊ณต")
}
}
}
```