Sobes.tech

Коя версия на езика Swift се използва в проекта — по-горе или по-ниско от 6?

Senior
Salmon
51

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

Има ли още макроси в проекта освен мрежовия слой?

Senior
Salmon
49

Защо текущият код с безкраен цикъл for в main не работи? Как да го поправим?

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

Какъв е минималният таргет iOS в проекта сега?

Senior
Salmon
47

Какво се използва за презентационните модули в UIKit и SwiftUI — каква архитектура?

Senior
Salmon
44

Използвате ли архитектурата Viper за UIKit? Това важи за всички приложения?

Senior
Salmon
44

Има ли проблеми с конкуренцията (Sendable, unchecked Sendable, преход между актьорите) в модулите, с които работихте директно?

Senior
Salmon
43

Защо избрахте речник като съхранение на кеша?

Middle+
RevolutRevolut
43

Колко ти помагат инструментите за ИИ (Cursor, Proxyman и т.н.) да бъдеш по-продуктивен на работното място?

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

Self -> Задача -> (силен) Self .... Обратно -> View desinit -> View model deinit?

Senior
Salmon
42

Използвате ли в момента GCD или Modern Concurrency (async/await) за нови задачи, свързани с нишки?

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
40

Разкажи повече за последния си проект — модула за фотогалерия в Авито, за който отговаряше (краткосрочен наем, форма за резервация и т.н.)

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

Имаше ли интересни сесии/рамки на последната WWDC, които бихте искали да опитате да приложите в работата си?

Senior
Salmon
38

Кога и как се случва отменянето при използване на 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
/206