iOS
Was passiert, wenn nil an set übergeben wird?
Wie funktioniert das Design-System zwischen UIKit und SwiftUI — gibt es Duplikate von Komponenten oder Wrappers?
Protokoll SomeProtocol {} func test1_1(wert: SomeProtocol) {} func test1_2(wert: 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)) } } ``` Das Ziel scheint darin zu bestehen, einen SwiftUI-Button-Stil anzupassen, indem mit verschiedenen Modifikatoren wie Padding, Vordergrundfarbe, Rahmenbreite, Hintergrundfarbe und Zuschneideform experimentiert wird. Die Frage bezieht sich wahrscheinlich auf das Beheben oder Verbessern des Button-Stils, um ein gewünschtes Erscheinungsbild oder Verhalten zu erzielen, z. B. den Button die verfügbare Breite ausfüllen zu lassen oder den visuellen Stil anzupassen.
Protokoll SomeProtocol {} func test1_1(wert: SomeProtocol) {} func test2_1(wert: some SomeProtocol) {} func test1_2(wert: any SomeProtocol) {}
Verwenden Sie derzeit GCD oder Modern Concurrency (async/await) für neue Aufgaben im Zusammenhang mit Threads?
Als du zum Projekt kamst, war Swift 6 bereits vorhanden, oder fand der Übergang während deiner Zeit statt?
```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 } } } ```
Protokoll SomeProtocol { func test() } func test1_1(wert: SomeProtocol) {} func test1_2(wert: any SomeProtocol) {} func test2_1(wert: some SomeProtocol) {} func test2_2<Wert: SomeProtocol>(wert: Wert) {} class A { func test2_2<Wert: SomeProtocol>(wert: Wert) { } } class B: SomeProtocol { func test() {} } class C: B {} A().test2_2(wert: B())
Gab es Probleme mit der Konkurrenz (Sendable, unchecked Sendable, Übergänge zwischen Akteuren) in den Modulen, mit denen Sie direkt gearbeitet haben?
Was wird für Präsentationsmodule in UIKit und SwiftUI verwendet — welche Architektur?
Wann und wie erfolgt die Stornierung bei Verwendung von DispatchQueue mit WorkItem und Aufruf von cancel()?
@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("Fehler beim Herunterladen des Bildes: \(error)") } } } Button("Herunterladen") { onDownloadPhoto(url) }
Wenn du eine wiederverwendbare Button-Komponente für ein Design-System in SwiftUI mit verschiedenen Stilen (primär/sekundär) entwerfen würdest, wie würdest du das umsetzen?
Gibt es im Projekt noch weitere Makros außer der Netzwerkschicht?
Stellen Sie sich kurz vor und beschreiben Sie Ihre aktuelle Arbeit.
endgültige Klasse 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) } }
Gab es auf der letzten WWDC interessante Sitzungen oder Frameworks, die Sie in Ihrer Arbeit ausprobieren möchten?
Erzähle mir von der Verwendung von SwiftUI im Projekt — welche Richtlinien gibt es, wie viele Bildschirme sind in SwiftUI geschrieben?
Protokoll 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()