iOS
Оё архитектураи Viper барои UIKit истифода мебаред? Ин ба ҳама барномаҳо дахл дорад?
протокол SomeProtocol {} func test1_1(қимат: SomeProtocol) {} func test1_2(қимат: any SomeProtocol) {}
соңғы сынып 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) } }
Оё дар лоиҳа макросҳои дигар ба ғайр аз қабати шабака ҳастанд?
протокол SomeProtocol {} функсия test1_1 арзиши: SomeProtocol {} функсия test2_1 арзиши: some SomeProtocol {} функсия test1_2 арзиши: any SomeProtocol {}
Оё ҳоло GCD ё Modern Concurrency (async/await)-ро барои вазифаҳои нав, ки бо сӯрохиҳо алоқаманданд, истифода мебаред?
Self -> Вазифа -> (қувватли) Self .... Бозгашт -> View desinit -> View model deinit?
Чӣ гуна View ва ViewModel дар UIKit муошират мекунанд — оё чизе монанди RxSwift/Combine барои биндингҳо истифода мешавад?
@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) }
```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 } } } ```
Чӣ қадар ба шумо кӯмак мерасонанд асбобҳои зеҳни сунъӣ (Cursor, Proxyman ва ғайра) дар баланд бардоштани истеҳсолот дар кор?
```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.
Агар шумо як компонент барои тугмаи такрорӣ барои системаи тарҳрезӣ дар SwiftUI бо услубҳои гуногун (асосӣ/дуюмӣ) тарҳрезӣ мекардед, шумо онро чӣ гуна иҷро мекардед?
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)) } }
Оё дар модулҳое, ки шумо мустақиман кор мекардед, мушкилоти рақобат (Sendable, unchecked Sendable, гузариш байни актёрҳо) вуҷуд дошт?
Хусусиятро кӯтоҳ баён кунед ва коре, ки ҳоло мекунед, тавсиф кунед.
Бихонед бештар дар бораи лоиҳати охирини худ — модулҳои галереи акс дар Авито, ки шумо масъул будед (ишёри кӯтоҳмуддат, формасозии брон, ва ғайра)
протокол 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())
Кай ва чӣ гуна рух медиҳад бекор кардан вақте ки бо DispatchQueue бо WorkItem кор мекунед ва cancel()-ро даъват мекунед?
Чаро шумо луғатро ҳамчун захираи кеш интихоб кардед?