Sobes.tech

Jei įgyvendinate naują ekraną ar naują funkciją, ar rašote iš karto SwiftUI, ar yra diskusijų dėl pasirinkimo tarp UIKit ir SwiftUI?

Senior
Salmon
28

Kodėl pasirinkote žodyną kaip talpyklos saugyklą?

Middle+
RevolutRevolut
28

Ar paskutinėje WWDC buvo įdomių sesijų/arba karkasų, kuriuos norėtumėte išbandyti savo darbe?

Senior
Salmon
28

paskutinė klasė Cache<T>: CacheProtocol { func getValue(forKey key: String) -> T? { return storage[key] } func fetchValue(forKey key: String, completion: @escaping (T?) -> Void) { let value = storage[key] completion(value) } } paskutinė klasė CacheTests: XCTestCase { override func setUp() { super.setUp() } func testSetAndGetValue() { let cache = Cache<String>() let key: String = "key" let value: String = "value" cache.setValue(value, forKey: key) XCTAssertEqual(cache.getValue(forKey: key), value) cache.setValue(nil, forKey: key) XCTAssertTrue(cache.getValue(forKey: key) == nil) } func testCompletion() { } } CacheTests.defaultTestSuite.run()

Middle+
RevolutRevolut
28

Papaskink apie SwiftUI naudojimą projekte — kokia yra politika, kiek ekranų parašyta SwiftUI

Senior
Salmon
27

Papaskink apie naudingus Property Wrapper'us, kuriuos naudojai projekte

Senior
Salmon
27

Kiek naudingi yra dirbtinio intelekto įrankiai (Cursor, Proxyman ir kt.), kad padidintum produktyvumą darbe?

Senior
Salmon
25

Kaip suprantate struktūruotą konkurenciją Swift? Ar Task.detached atitinka šią sąvoką?

Senior
Salmon
24

import UIKit protocol CacheProtocol { associatedtype Value func setValue(_ value: Value?, forKey key: String) func getValue(forKey key: String) -> Value? func fetchValue(forKey key: String, completion: @escaping (Value?) -> Void) } final class Cache<T>: CacheProtocol { private var storage: [String: T] = [:] private let queue = DispatchQueue(label: "my.queue", attributes: .concurrent) func setValue(_ value: T?, forKey key: String) { queue.sync(flags: .barrier) { storage[key] = value } } func getValue(forKey key: String) -> T? { queue.sync { return storage[key] } } func fetchValue(forKey key: String, completion: @escaping (T?) -> Void) { queue.async { let value = self.storage[key] completion(value) } } }

Middle+
RevolutRevolut
24

import UIKit protokolas CacheProtocol { associatedtype Value func setValue(_ value: Value?, forKey key: String) func value(forKey key: String) -> Value? func fetchValue(forKey key: String, completion: @escaping (Value?) -> Void) }

Middle+
RevolutRevolut
24

Paaiškinkite skirtumą tarp atmintyje esančio talpyklos ir diske esančio talpyklos.

Middle+
RevolutRevolut
23

Kodėl sukūrėte atskiras load ir getLastCities metodus, ir kas turėtų įvykti, jei getLastCities yra iškviesta prieš duomenų įkėlimą?

Senior
Uzum
23

Kaip jūs nustatytumėte prioritetus identifikuotiems klausimams, jei projektas turi būti gamyboje per valandą?

Senior
Uzum
22

// Rašo `data` į failą, pavadintą `file`. func writeData(_ data: Data, to file: String) { let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! let fileURL = documentDirectoryURL.appendingPathComponent(file) try? data.write(to: fileURL) } // Pašalina failą, pavadintą `file`. func remove(file: String) { let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! let fileURL = documentDirectoryURL.appendingPathComponent(file) try? FileManager.default.removeItem(at: fileURL) } // Skaito `Data` iš failo, pavadinto `file`. Jei failas neegzistuoja, grąžina `nil`. func readData(from file: String) -> Data? { let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! let fileURL = documentDirectoryURL.appendingPathComponent(file) return try? Data(contentsOf: fileURL) } final class DiskCache<T>: CacheProtocol { func setValue(_ value: T?, forKey key: String) { } func getValue(forKey key: String) -> T? { } func fetchValue(forKey key: String, completion: @escaping (T?) -> Void) { } }

Middle+
RevolutRevolut
22

Kodėl naudoti galutinį klasę vietoj klasės krovimo įgyvendinimui?

Middle+
RevolutRevolut
16

enum HTTPMethod: String { case post = "POST" } enum Errors: Error { case invalidUrl case invalidQuery case invalidResponse case httpStatus(Int) } protocol MyDecoder { func decode<T: Decodable>(_: _ type: T.Type, from data: Data) throws -> T } final class NetworkService { private let session: URLSession private let encoder = JSONEncoder() private let decoder: MyDecoder init( session: URLSession = .shared, decoder: MyDecoder ) { self.session = session self.decoder = decoder } 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)

Middle+
СБЕРСБЕР
7

// Paslauga, kuri siunčia užklausas (get/post), url, užklausos formavimas pagal semantiką (decode/encode)

Middle+
СБЕРСБЕР
7
/206