iOS
protokół SomeProtocol {} func test1_1(wartość: SomeProtocol) {} func test2_1(wartość: some SomeProtocol) {} func test1_2(wartość: any SomeProtocol) {}
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)) } }
Co się dzieje, gdy nil jest przekazywane do set?
protokół SomeProtocol {} func test1_1(wartość: SomeProtocol) {} func test1_2(wartość: 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)) } } ``` Wygląda na to, że celem jest dostosowanie stylu przycisku SwiftUI, eksperymentując z różnymi modyfikatorami takimi jak padding, kolor pierwszego planu, szerokość ramki, kolor tła i kształt przycinania. Prawdopodobnie pytanie dotyczy naprawy lub ulepszenia stylu przycisku, aby osiągnąć pożądany wygląd lub zachowanie, na przykład sprawić, by przycisk wypełnił całą dostępną szerokość lub dostosować jego styl wizualny.
Czy obecnie używasz GCD lub Modern Concurrency (async/await) do nowych zadań związanych z wątkami?
Kiedy dołączyłeś do projektu, czy Swift 6 już istniał, czy przejście nastąpiło podczas twojego udziału?
```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 } } } ```
protokół SomeProtocol { func test() } func test1_1(wartość: SomeProtocol) {} func test1_2(wartość: any SomeProtocol) {} func test2_1(wartość: some SomeProtocol) {} func test2_2<Wartość: SomeProtocol>(wartość: Wartość) {} class A { func test2_2<Wartość: SomeProtocol>(wartość: Wartość) { } } class B: SomeProtocol { func test() {} } class C: B {} A().test2_2(wartość: B())
Czy wystąpiły problemy z konkurencyjnością (Sendable, unchecked Sendable, przejścia między aktorami) w modułach, z którymi bezpośrednio pracowałeś?
Co jest używane do modułów prezentacyjnych w UIKit i SwiftUI — jaka architektura?
Kiedy i jak następuje anulowanie, gdy używa się DispatchQueue z WorkItem i wywołuje 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("Nie udało się pobrać obrazu: \(error)") } } } Button("Pobierz") { onDownloadPhoto(url) }
klasa final 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) } }
Gdybyś projektował wielokrotnego użytku komponent przycisku dla systemu projektowania w SwiftUI z różnymi stylami (primary/secondary), jak byś to zrealizował?
Czy w projekcie są jeszcze jakieś makra oprócz warstwy sieciowej?
Krótko przedstaw się i opisz swoją obecną pracę.
Czy na ostatniej WWDC były interesujące sesje/frameworki, które chciałbyś wypróbować w pracy?
Opowiedz o użyciu SwiftUI w projekcie — jaka jest polityka, ile ekranów jest napisanych w SwiftUI
protokół 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()