iOS
Jei įgyvendinate naują ekraną ar naują funkciją, ar rašote iš karto SwiftUI, ar yra diskusijų dėl pasirinkimo tarp UIKit ir SwiftUI?
Kodėl pasirinkote žodyną kaip talpyklos saugyklą?
Ar paskutinėje WWDC buvo įdomių sesijų/arba karkasų, kuriuos norėtumėte išbandyti savo darbe?
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()
Papaskink apie SwiftUI naudojimą projekte — kokia yra politika, kiek ekranų parašyta SwiftUI
Papaskink apie naudingus Property Wrapper'us, kuriuos naudojai projekte
Kiek naudingi yra dirbtinio intelekto įrankiai (Cursor, Proxyman ir kt.), kad padidintum produktyvumą darbe?
Kaip suprantate struktūruotą konkurenciją Swift? Ar Task.detached atitinka šią sąvoką?
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) } } }
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) }
Paaiškinkite skirtumą tarp atmintyje esančio talpyklos ir diske esančio talpyklos.
Kodėl sukūrėte atskiras load ir getLastCities metodus, ir kas turėtų įvykti, jei getLastCities yra iškviesta prieš duomenų įkėlimą?
Kaip jūs nustatytumėte prioritetus identifikuotiems klausimams, jei projektas turi būti gamyboje per valandą?
// 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) { } }
Kodėl naudoti galutinį klasę vietoj klasės krovimo įgyvendinimui?
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)
// Paslauga, kuri siunčia užklausas (get/post), url, užklausos formavimas pagal semantiką (decode/encode)