Sobes.tech

Оё архитектураи Viper барои UIKit истифода мебаред? Ин ба ҳама барномаҳо дахл дорад?

Senior
Salmon
43

протокол SomeProtocol {} func test1_1(қимат: SomeProtocol) {} func test1_2(қимат: any SomeProtocol) {}

Senior
Salmon
42

соңғы сынып 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+
СБЕРСБЕР
41

Оё дар лоиҳа макросҳои дигар ба ғайр аз қабати шабака ҳастанд?

Senior
Salmon
41

протокол SomeProtocol {} функсия test1_1 арзиши: SomeProtocol {} функсия test2_1 арзиши: some SomeProtocol {} функсия test1_2 арзиши: any SomeProtocol {}

Senior
Salmon
40

Оё ҳоло GCD ё Modern Concurrency (async/await)-ро барои вазифаҳои нав, ки бо сӯрохиҳо алоқаманданд, истифода мебаред?

Senior
Salmon
40

Self -> Вазифа -> (қувватли) Self .... Бозгашт -> View desinit -> View model deinit?

Senior
Salmon
39

Чӣ гуна View ва ViewModel дар UIKit муошират мекунанд — оё чизе монанди RxSwift/Combine барои биндингҳо истифода мешавад?

Senior
Salmon
39

@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("Қатолик: суретті жүктеу сәтсіз аяқталды: \(error)") } } } Button("Жүктеу") { onDownloadPhoto(url) }

Senior
Salmon
39

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

Чӣ қадар ба шумо кӯмак мерасонанд асбобҳои зеҳни сунъӣ (Cursor, Proxyman ва ғайра) дар баланд бардоштани истеҳсолот дар кор?

Senior
Salmon
38

```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)) } } ``` Výzva se zdá být o přizpůsobení stylu tlačítka SwiftUI, experimentování s různými modifikátory, jako je odsazení, barva popředí, šířka rámečku, barva pozadí a tvar oříznutí. Otázka pravděpodobně zahrnuje opravu nebo vylepšení stylu tlačítka tak, aby dosáhla požadovaného vzhledu nebo chování, například aby tlačítko vyplnilo dostupnou šířku nebo upravit jeho vizuální styl.

Senior
Salmon
38

Агар шумо як компонент барои тугмаи такрорӣ барои системаи тарҳрезӣ дар SwiftUI бо услубҳои гуногун (асосӣ/дуюмӣ) тарҳрезӣ мекардед, шумо онро чӣ гуна иҷро мекардед?

Senior
Salmon
37

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
37

Оё дар модулҳое, ки шумо мустақиман кор мекардед, мушкилоти рақобат (Sendable, unchecked Sendable, гузариш байни актёрҳо) вуҷуд дошт?

Senior
Salmon
37

Хусусиятро кӯтоҳ баён кунед ва коре, ки ҳоло мекунед, тавсиф кунед.

Middle+
RevolutRevolut
36

Бихонед бештар дар бораи лоиҳати охирини худ — модулҳои галереи акс дар Авито, ки шумо масъул будед (ишёри кӯтоҳмуддат, формасозии брон, ва ғайра)

Senior
Salmon
36

протокол SomeProtocol { func test() } func test1_1(қиммат: SomeProtocol) {} func test1_2(қиммат: any SomeProtocol) {} func test2_1(қиммат: some SomeProtocol) {} func test2_2<Қиммат: SomeProtocol>(қиммат: Қиммат) {} class A { func test2_2<Қиммат: SomeProtocol>(қиммат: Қиммат) { } } class B: SomeProtocol { func test() {} } class C: B {} A().test2_2(қиммат: B())

Senior
Salmon
35

Кай ва чӣ гуна рух медиҳад бекор кардан вақте ки бо DispatchQueue бо WorkItem кор мекунед ва cancel()-ро даъват мекунед?

Senior
Salmon
35

Чаро шумо луғатро ҳамчун захираи кеш интихоб кардед?

Middle+
RevolutRevolut
35
/206