Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : Groupe Ka — app iOS native7// File : GroupeKa/Core/ImageDistante.swift8// Module : Groupe Ka9// Repository : https://git.spboucher.ai/groupe-ka-ios10// Project Website : Not specified11// Created : 2026-12-0312// Last Modified : 2026-12-0313//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI4243/// Chargeur d'images distantes (captures des sites, photos d'annonces) : mémoire, puis cache HTTP du système.44actor Images {45 static let partagees = Images()46 private let memoire = NSCache<NSURL, UIImage>()47 private let session: URLSession4849 init() {50 let c = URLSessionConfiguration.default51 c.urlCache = URLCache(memoryCapacity: 8 << 20, diskCapacity: 120 << 20)52 c.requestCachePolicy = .returnCacheDataElseLoad53 c.timeoutIntervalForRequest = 2054 session = URLSession(configuration: c)55 memoire.countLimit = 8056 }5758 func image(_ url: URL) async -> UIImage? {59 if let i = memoire.object(forKey: url as NSURL) { return i }60 guard let (d, r) = try? await session.data(from: url), (r as? HTTPURLResponse)?.statusCode == 200,61 let i = UIImage(data: d), let pret = await i.byPreparingForDisplay() else { return nil }62 memoire.setObject(pret, forKey: url as NSURL)63 return pret64 }65}6667/// Image distante dans un cadre aux proportions connues : rien ne saute au chargement. Si l'image ne vient pas,68/// le cadre reste vide (un aplat), sans image de remplacement inventée.69struct ImageDistante: View {70 let url: URL?71 var remplir = true72 @State private var image: UIImage?7374 var body: some View {75 ZStack {76 Ka.sol77 if let image {78 Image(uiImage: image).resizable().aspectRatio(contentMode: remplir ? .fill : .fit).transition(.opacity)79 }80 }81 .task(id: url) {82 guard let url else { image = nil; return }83 let i = await Images.partagees.image(url)84 withAnimation(.easeOut(duration: 0.25)) { image = i }85 }86 }87}88