Sobes.tech

Ինչպես են հաղորդակցվում View և ViewModel-ը UIKit-ում — օգտագործվում է ինչ-որ բան, ինչպես RxSwift/Combine բինդինգների համար?

Senior
Salmon
48

Կա՞ն այլ մակրոներ նախագծում բացի ցանցային շերտից։

Senior
Salmon
48

Ինչու է ներկայիս կոդը, որը պարունակում է անսահման for ցիկլ main-ում, չի աշխատում: Ինչպես դա ուղղել?

Principal
Позитив Технолоджис
48

Ի՞նչ տարբերակ է օգտագործվում Swift լեզվում՝ ավելի բարձր 6-ից կամ ցածր?

Senior
Salmon
47

Ի՞նչ է ներկայումս նվազագույն iOS նպատակն նախագծում։

Senior
Salmon
45

Օգտագործում եք Viper ճարտարապետությունը UIKit-ի համար: Դա վերաբերում է բոլոր հավելվածներին:

Senior
Salmon
44

@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
43

struct ExampleView: View { @State var isVariant1 = true var body: some View { VStack { Toggle("Օգտագործել տարբերակը 1", isOn: $isVariant1.animation(.linear)) Text(isVariant1 ? "Տարբերակ 1" : "Տարբերակ 2") } .padding() } } Տարբերակ1 -> չափս -> 1 -> 0 Տարբերակ2 -> չափս -> 0

Senior
Salmon
43

վերջնական դասը 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+
СБЕРСБЕР
42

Ինչու եք ընտրել բառարան որպես կեշ պահեստավորում?

Middle+
RevolutRevolut
42

Ի՞նչ չափով են Ձեզ օգնում արհեստական բանականության գործիքները (Cursor, Proxyman և այլն) աշխատունակությունը բարձրացնելուն:

Senior
Salmon
42

Self -> Տվյալ -> (ուժեղ) Self .... Հետ -> View desinit -> View model deinit?

Senior
Salmon
41

Դուք արդյոք ներկայում օգտագործում եք GCD կամ Modern Concurrency (async/await) նոր առաջադրանքների համար, որոնք կապված են թելերով?

Senior
Salmon
40

Ի՞նչ է օգտագործվում UIKit և SwiftUI-ում ներկայացման մոդուլների համար — ո՞ր ճարտարապետությունն է:

Senior
Salmon
40

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

Կա՞ն խնդիրներ մրցակցայինության հետ (Sendable, unchecked Sendable, անցումներ դերակատարների միջև) այն մոդուլներում, որոնց հետ դուք ուղղակի աշխատել եք։

Senior
Salmon
39

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

Երբ և ինչպես է տեղի ունենում չեղարկումը, երբ օգտագործվում է DispatchQueue-ով WorkItem և կանչվում է cancel()?

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

Ավելացրեք ավելի մանրամասն ձեր վերջին նախագծի մասին — լուսանկարների գալերեայի մոդուլը Ավիտոյում, որի պատասխանատուն եք (կարճաժամկետ վարձակալություն, ամրագրման ձևանմուշ և այլն)

Senior
Salmon
36
/206