iOS
Cosa succede quando nil viene passato a set?
Come funziona il sistema di progettazione tra UIKit e SwiftUI — ci sono duplicazioni di componenti o wrapper?
protocollo SomeProtocol {} func test1_1(valore: SomeProtocol) {} func test1_2(valore: any SomeProtocol) {}
```swift struct CustomButtonStyleView: View { var body: some View { VStack { Button("Button") { print("Tapped") } .buttonStyle(CustomButtonStyle()) } } } private struct CustomButtonStyle: ButtonStyle { func makeBody(configuration: Configuration) -> some View { configuration.label .padding() .foregroundColor(.white) .background(Color.red) .clipShape(RoundedRectangle(cornerRadius: 8)) } } ``` ```swift struct CustomButtonStyleView: View { var body: some View { VStack { Button("Button") { print("Tapped") } .buttonStyle(CustomButtonStyle()) } } } private struct CustomButtonStyle: ButtonStyle { func makeBody(configuration: Configuration) -> some View { configuration.label .padding() .foregroundColor(.white) .frame(maxWidth?) .background(Color.red) .clipShape(RoundedRectangle(cornerRadius: 8)) } } ``` ```swift struct CustomButtonStyleView: View { var body: some View { VStack { Button("Button") { print("Tapped") } .buttonStyle(CustomButtonStyle()) } } } private struct CustomButtonStyle: ButtonStyle { func makeBody(configuration: Configuration) -> some View { configuration.label //.padding() //.foregroundColor(.white) .frame(maxWidth: .infinity) .background(Color.red) //.clipShape(RoundedRectangle(cornerRadius: 8)) } } ``` ```swift struct CustomButtonStyleView: View { var body: some View { VStack { Button("Button") { print("Tapped") } .buttonStyle(CustomButtonStyle()) .frame(width: 200) } } } private struct CustomButtonStyle: ButtonStyle { func makeBody(configuration: Configuration) -> some View { configuration.label //.padding() //.foregroundColor(.white) .frame(maxWidth: .infinity) .background(Color.red) //.clipShape(RoundedRectangle(cornerRadius: 8)) } } ``` L'obiettivo sembra essere di personalizzare uno stile di pulsante SwiftUI, sperimentando con diversi modificatori come padding, colore in primo piano, larghezza del frame, colore di sfondo e forma di ritaglio. La domanda probabilmente riguarda la correzione o il miglioramento dello stile del pulsante per ottenere un aspetto o un comportamento desiderato, come far sì che il pulsante riempia tutta la larghezza disponibile o regolare il suo stile visivo.
protocollo SomeProtocol {} func test1_1(valore: SomeProtocol) {} func test2_1(valore: some SomeProtocol) {} func test1_2(valore: any SomeProtocol) {}
Attualmente utilizzi GCD o Modern Concurrency (async/await) per nuovi compiti legati ai thread?
Quando sei arrivato al progetto, c'era già Swift 6, o il passaggio è avvenuto durante il tuo periodo?
Ci sono stati problemi di concorrenza (Sendable, Sendable non verificato, transizioni tra attori) nei moduli con cui hai lavorato direttamente?
protocol SomeProtocol { func test() } func test1_1(valore: SomeProtocol) {} func test1_2(valore: any SomeProtocol) {} func test2_1(valore: some SomeProtocol) {} func test2_2<Valore: SomeProtocol>(valore: Valore) {} class A { func test2_2<Valore: SomeProtocol>(valore: Valore) { } } class B: SomeProtocol { func test() {} } class C: B {} A().test2_2(valore: B())
```swift struct ContentView: View { var body: some View { ScrollView { content .padding(20) } .background(Color(.systemGroupedBackground)) .overlay(alignment: .bottom) { continueButton } } } ``` ```swift struct ContentView: View { var body: some View { ScrollView { content .padding(20) } .background(Color(.systemGroupedBackground)) .safeAreaInset(edge: .bottom) { continueButton } } } ```
@MainActor final class ViewModel: ObservableObject { @Published var image: UIImage? func onDownloadPhoto(url: URL) { do { let data = try Data(contentsOf: url) image = UIImage.init(data: data) } catch { log.error("Impossibile scaricare l'immagine: \(error)") } } } Button("Scarica") { onDownloadPhoto(url) }
Ci sono altri macro nel progetto oltre allo strato di rete?
Presentati brevemente e descrivi il tuo lavoro attuale.
classe finale NetworkService { func request<Response: Decodable, Body: Encodable>(urlString: String, method: HTTPMethod, body: Body? = nil, headers: [String: String] = [:], query: [String: String] = [:]) async throws -> Response { guard var components = URLComponents(string: urlString) else { throw Errors.invalidUrl } if !query.isEmpty { components.queryItems = query.map { URLQueryItem(name: $0.key, value: $0.value) } } guard let url = components.url else { throw Errors.invalidQuery } var request = URLRequest(url: url) request.httpMethod = method.rawValue headers.forEach { request.setValue($0.value, forHTTPHeaderField: $0.key) } if let body, method == .post { request.httpBody = try encoder.encode(body) // ? } let (data, response) = try await session.data(for: request) guard let httpResponse = response as? HTTPURLResponse else { throw Errors.invalidResponse } guard (200...299).contains(httpResponse.statusCode) else { throw Errors.httpStatus(httpResponse.statusCode) } return try decoder.decode(Response.self, from: data) } }
Cosa viene utilizzato per i moduli di presentazione in UIKit e SwiftUI — quale architettura?
Quando e come avviene l'annullamento utilizzando DispatchQueue con WorkItem e chiamando cancel()?
Ci sono state sessioni o framework interessanti all'ultima WWDC che vorresti provare ad applicare nel tuo lavoro?
Parlami dell'uso di SwiftUI nel progetto — qual è la politica, quante schermate sono scritte in SwiftUI
Se stessi progettando un componente di pulsante riutilizzabile per un sistema di design in SwiftUI con stili diversi (primario/secundario), come lo implementeresti?
protocollo CacheProtocol { associatedtype Value func setValue(_ value: Value?, forKey key: String) func getValue(forKey key: String) -> Value? func fetchValue(forKey key: String, completion: @escaping (Value?) -> Void) } final class Cache<T>: CacheProtocol { private var storage: [String: T] = [:] func setValue(_ value: T?, forKey key: String) { storage[key] = value } func getValue(forKey key: String) -> T? { return storage[key] } func fetchValue(forKey key: String, completion: @escaping (T?) -> Void) { let value = storage[key] completion(value) } } import XCTest final class CacheTests: XCTestCase { override func setUp() { super.setUp() } func testSetAndGetValue() { let cache = Cache<String>() let key: String = "key" let value: String = "value" cache.setValue(value, forKey: key) XCTAssertEqual(cache.getValue(forKey: key), value) cache.setValue(nil, forKey: key) XCTAssertTrue(cache.getValue(forKey: key) == nil) } } CacheTests.defaultTestSuite.run()