SPB Git

Repository Public

Spotlight.swift 6.3 KB 139 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Immo-Ka iOS9// File             : ImmoKa/System/Spotlight.swift10// Description      : recherche Spotlight — les favoris et les fiches consultées11//                    sont retrouvables depuis l'écran d'accueil ; rien d'autre12//                    n'est indexé, et tout reste sur l'appareil.13// Module           : ImmoKa14// Repository       : https://git.spboucher.ai/immo-ka-ios-v315// Project Website  : https://www.immo-ka.com16// Created          : 2026-11-2817// Last Modified    : 2026-11-2818//19// =============================================================================20// AUTHOR & PROFESSIONAL AFFILIATION21// =============================================================================22//23// Author           : Simon-Pierre Boucher24// Position         : Professor of Finance25// Institution      : Université du Québec en Outaouais (UQO)26// Department       : Département des sciences administratives27// Organization     : SP Boucher28//29// Website          : https://spboucher.ai30// Git              : https://git.spboucher.ai31//32// =============================================================================33// OFFICIAL CONTACT DIRECTORY34// =============================================================================35//36// General          : info@spboucher.ai37// Professional     : contact@spboucher.ai38// Direct           : simon@spboucher.ai39// Research         : research@spboucher.ai40// Development      : dev@spboucher.ai41// Support          : support@spboucher.ai42// Security/Admin   : admin@spboucher.ai43// Notifications    : notifications@spboucher.ai44//45// Preferred Contact: support@spboucher.ai46//47// =============================================================================48// COPYRIGHT & INTELLECTUAL PROPERTY49// =============================================================================50//51// Copyright (c) 202652// Simon-Pierre Boucher53//54// All rights reserved where applicable.55//56// This file is governed by the applicable project license,57// copyright notices, institutional agreements and relevant law.58//59// Unless expressly authorized by the applicable license or60// rights holder, copying, redistribution, sublicensing,61// publication and commercial exploitation are not permitted.62//63// Existing third-party rights and notices remain unaffected.64//65// =============================================================================66// CONFIDENTIALITY & SECURITY67// =============================================================================68//69// Classification   : Public70// Distribution     : Public repository; use is governed by the project license71// Security Contact : admin@spboucher.ai72//73// Access to this source does not independently grant permission74// to redistribute or disclose confidential materials.75//76// Do not embed credentials, private keys, access tokens,77// certificates or confidential personal information.78//79// =============================================================================80// LICENSE & MAINTENANCE81// =============================================================================82//83// License          : None specified (no license file in this repository)84// Maintainer       : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import CoreSpotlight92import Foundation93import UniformTypeIdentifiers9495enum Spotlight {96    static let favoritesDomain = "favoris"97    static let seenDomain = "consultees"9899    /// Identifiant Spotlight d'une propriété : son domaine et son identifiant d'inscription.100    static func identifier(_ uid: String, domain: String) -> String { "\(domain)|\(uid)" }101102    /// Identifiant d'inscription porté par une activité Spotlight.103    static func uid(from identifier: String) -> String? {104        guard let i = identifier.firstIndex(of: "|") else { return nil }105        let uid = String(identifier[identifier.index(after: i)...])106        return uid.isEmpty ? nil : uid107    }108109    /// Ce que Spotlight montre d'une propriété (fonction pure, testée).110    static func attributes(title: String, city: String, sector: String, kind: String, price: Double?, facts: String) -> CSSearchableItemAttributeSet {111        let a = CSSearchableItemAttributeSet(contentType: .content)112        a.title = title113        let place = [sector.isEmpty || sector == city ? nil : sector, city.isEmpty ? nil : city].compactMap { $0 }.joined(separator: ", ")114        a.contentDescription = [price.map { Fmt.money($0) + " demandés" }, place.isEmpty ? nil : place, facts.isEmpty ? nil : facts]115            .compactMap { $0 }.joined(separator: " · ")116        a.keywords = [city, sector, kind, "à vendre", "propriété", "Immo-Ka"].filter { !$0.isEmpty }117        a.city = city.isEmpty ? nil : city118        a.stateOrProvince = "Québec"119        return a120    }121122    static func index(uid: String, domain: String, title: String, city: String, sector: String, kind: String, price: Double?, facts: String) {123        guard CSSearchableIndex.isIndexingAvailable() else { return }124        let item = CSSearchableItem(uniqueIdentifier: identifier(uid, domain: domain), domainIdentifier: domain,125                                    attributeSet: attributes(title: title, city: city, sector: sector, kind: kind, price: price, facts: facts))126        // une fiche consultée s'efface d'elle-même après 30 jours ; un favori reste tant qu'il est favori127        item.expirationDate = domain == seenDomain ? Date().addingTimeInterval(30 * 86400) : .distantFuture128        CSSearchableIndex.default().indexSearchableItems([item]) { _ in }129    }130131    static func remove(uid: String, domain: String) {132        CSSearchableIndex.default().deleteSearchableItems(withIdentifiers: [identifier(uid, domain: domain)]) { _ in }133    }134135    static func removeAll(domain: String) {136        CSSearchableIndex.default().deleteSearchableItems(withDomainIdentifiers: [domain]) { _ in }137    }138}139
Files main
Menu

Theme