iOS
protokoll SomeProtocol {} funktsioon test1_1 väärtus: SomeProtocol {} funktsioon test2_1 väärtus: some SomeProtocol {} funktsioon test1_2 väärtus: any SomeProtocol {}
protokoll SomeProtocol {} func test1_1(väärtus: SomeProtocol) {} func test1_2(väärtus: any SomeProtocol) {}
Kuidas suhtlevad View ja ViewModel UIKitus — kas sarnast RxSwift/Combine kasutamist sidumiste jaoks?
```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 } } } ```
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()) } } } 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)) } } ```
Kas kasutate praegu GCD või Modern Concurrency (async/await) uusi ülesandeid, mis on seotud niitidega?
Kui sa tulid projekti, kas Swift 6 juba olemas või toimus üleminek sinu ajal?
Lõplik klass NetworkService, mis tegeleb võrgupäringutega, on kirjutatud Swift keeles ja kasutab asünkroonseid funktsioone koos generiliste parameetrite Response ja Bodyga, et sobitada vastavalt Decodable ja Encodable protokollidele. Kood kontrollib URL-i, seadistab päised, saadab päringu ja töötleb vastust, kontrollides staatuskoodi ning dekodeerides andmeid vastavalt Response tüübile.
protokoll SomeProtocol { func test() } func test1_1(ülesanne: SomeProtocol) {} func test1_2(ülesanne: any SomeProtocol) {} func test2_1(ülesanne: some SomeProtocol) {} func test2_2<Ülesanne: SomeProtocol>(ülesanne: Ülesanne) {} class A { func test2_2<Ülesanne: SomeProtocol>(ülesanne: Ülesanne) { } } class B: SomeProtocol { func test() {} } class C: B {} A().test2_2(ülesanne: B())
Millal ja kuidas toimub tühistamine, kasutades DispatchQueue koos WorkItem ja kutsudes cancel()?
Kas oli probleeme konkurentsivõimega (Sendable, unchecked Sendable, üleminek aktorite vahel) modulites, millega otseselt töötasite?
@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("Neizdevās lejupielādēt attēlu: \(error)") } } } Button("Lejupielādēt") { onDownloadPhoto(url) }
Self -> Ülesanne -> (tugev) Self .... Tagasi -> View desinit -> View model deinit?
Mis kasutatakse UIKit ja SwiftUI esitlusmoodulite jaoks — milline arhitektuur?
Lühidalt tutvustage end ja kirjeldage oma praegust tööd.
Kui te kujundaksite korduvkasutatava nupu komponendi SwiftUI disainisüsteemile erinevate stiilidega (esmane/sekundaarne), kuidas te seda rakendaksite?
Kas projektis sisaldab veel makro-sid, välja arvatud võrgu kiht?
Kui te rakendate uue ekraani või uue funktsiooni, kas kirjutate kohe SwiftUI-s või on arutelusid UIKit ja SwiftUI valiku üle?
Räägi mulle oma viimase projekti kohta rohkem — Avito fotogalerii moodul, mille eest vastutasid (lühiajaline rent, broneerimisvorm jne.)