Sobes.tech

iOS

Cosa succede quando nil viene passato a set?

Middle+
RevolutRevolut
36

Come funziona il sistema di progettazione tra UIKit e SwiftUI — ci sono duplicazioni di componenti o wrapper?

Senior
Salmon
36

protocollo SomeProtocol {} func test1_1(valore: SomeProtocol) {} func test1_2(valore: any SomeProtocol) {}

Senior
Salmon
36

```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.

Senior
Salmon
36

protocollo SomeProtocol {} func test1_1(valore: SomeProtocol) {} func test2_1(valore: some SomeProtocol) {} func test1_2(valore: any SomeProtocol) {}

Senior
Salmon
35

Attualmente utilizzi GCD o Modern Concurrency (async/await) per nuovi compiti legati ai thread?

Senior
Salmon
35

Quando sei arrivato al progetto, c'era già Swift 6, o il passaggio è avvenuto durante il tuo periodo?

Senior
Salmon
34

Ci sono stati problemi di concorrenza (Sendable, Sendable non verificato, transizioni tra attori) nei moduli con cui hai lavorato direttamente?

Senior
Salmon
32

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())

Senior
Salmon
31

```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 } } } ```

Senior
Salmon
31

@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) }

Senior
Salmon
31

Ci sono altri macro nel progetto oltre allo strato di rete?

Senior
Salmon
30

Presentati brevemente e descrivi il tuo lavoro attuale.

Middle+
RevolutRevolut
29

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) } }

Middle+
СБЕРСБЕР
29

Cosa viene utilizzato per i moduli di presentazione in UIKit e SwiftUI — quale architettura?

Senior
Salmon
28

Quando e come avviene l'annullamento utilizzando DispatchQueue con WorkItem e chiamando cancel()?

Senior
Salmon
28

Ci sono state sessioni o framework interessanti all'ultima WWDC che vorresti provare ad applicare nel tuo lavoro?

Senior
Salmon
28

Parlami dell'uso di SwiftUI nel progetto — qual è la politica, quante schermate sono scritte in SwiftUI

Senior
Salmon
27

Se stessi progettando un componente di pulsante riutilizzabile per un sistema di design in SwiftUI con stili diversi (primario/secundario), come lo implementeresti?

Senior
Salmon
27

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()

Middle+
RevolutRevolut
26
/206