Sobes.tech

iOS

protokół SomeProtocol {} func test1_1(wartość: SomeProtocol) {} func test2_1(wartość: some SomeProtocol) {} func test1_2(wartość: any SomeProtocol) {}

Senior
Salmon
36

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

Senior
Salmon
36

Co się dzieje, gdy nil jest przekazywane do set?

Middle+
RevolutRevolut
36

protokół SomeProtocol {} func test1_1(wartość: SomeProtocol) {} func test1_2(wartość: 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)) } } ``` 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.

Senior
Salmon
36

Czy obecnie używasz GCD lub Modern Concurrency (async/await) do nowych zadań związanych z wątkami?

Senior
Salmon
35

Kiedy dołączyłeś do projektu, czy Swift 6 już istniał, czy przejście nastąpiło podczas twojego udziału?

Senior
Salmon
34

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

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

Senior
Salmon
33

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ś?

Senior
Salmon
32

Co jest używane do modułów prezentacyjnych w UIKit i SwiftUI — jaka architektura?

Senior
Salmon
31

Kiedy i jak następuje anulowanie, gdy używa się DispatchQueue z WorkItem i wywołuje cancel()?

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("Nie udało się pobrać obrazu: \(error)") } } } Button("Pobierz") { onDownloadPhoto(url) }

Senior
Salmon
31

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

Middle+
СБЕРСБЕР
30

Gdybyś projektował wielokrotnego użytku komponent przycisku dla systemu projektowania w SwiftUI z różnymi stylami (primary/secondary), jak byś to zrealizował?

Senior
Salmon
30

Czy w projekcie są jeszcze jakieś makra oprócz warstwy sieciowej?

Senior
Salmon
30

Krótko przedstaw się i opisz swoją obecną pracę.

Middle+
RevolutRevolut
29

Czy na ostatniej WWDC były interesujące sesje/frameworki, które chciałbyś wypróbować w pracy?

Senior
Salmon
28

Opowiedz o użyciu SwiftUI w projekcie — jaka jest polityka, ile ekranów jest napisanych w SwiftUI

Senior
Salmon
27

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

Middle+
RevolutRevolut
26
/206