Posts

Post not yet marked as solved
1 Replies
1.4k Views
I have the following protocol that a NetworkEngine conforms to: protocol NetworkEngineProtocol { func request<T: Decodable>(from endpoint: Endpoint) async throws -> T } This protocol is passed as a dependency into a custom ViewModel and I want to unit test the request method of the ViewModel, that itself calls the dependency request method. class ViewModel: ViewModelProtocol { var passthrough: PassthroughSubject<[SomeProperty], Never> = PassthroughSubject<[SomeProperty], Never>() private let networkEngine: NetworkEngineProtocol init(networkEngine: NetworkEngineProtocol) { self.networkEngine = networkEngine } func request() { Task { do { let model = try await networkEngine.request(from: .messages()) as CustomModel // ... do more stuff passthrough.send(someValue) // would want to test this } catch let err as NetworkEngineErrors { // ... error handling } } } } struct CustomModel: Decodable { let message: [String] let status: String } In order to Unit Test this method, I'd have to create a Mock class, that conforms to the NetworkEngineProtocol. Something like: class MockNetworkProtocol: NetworkEngineProtocol { init() {} func request<T>(from endpoint: Endpoint) async throws -> T where T : Decodable { // how to mock this? } } What's the best way to do this? How can I mock the request method of the NetworkEngine? Thanks
Posted Last updated
.
Post marked as solved
3 Replies
1.8k Views
I am encountering some weird behavior, where a subview within a UIBarButtonItem.customView is not firing the tapGesture. private var leftBarButtonItem: UIBarButtonItem = { let b = UIBarButtonItem() return b }() private lazy var imageView: UIImageView = { let iv = UIImageView() //... some adicional setup iv.isUserInteractionEnabled = true return iv }() func setupBBItem() { let holderView = UIView() holderView.isUserInteractionEnabled = true holderView.addSubview(imageView) imageView.frame = //... some frame //... more setups here holderView.isUserInteractionEnabled = true leftBarButtonItem.customView = holderView navigationItem.leftBarButtonItem = leftBarButtonItem let gesture = UITapGestureRecognizer(target: self, action: #selector(someFunction)) imageView.addGestureRecognizer(gesture) } @objc private func someFunction() { 	print("tap gesture detected") } I have even tried to add the gesture to the holderView instead, but the result is the same, the function never fires. Am I missing something here?
Posted Last updated
.
Post not yet marked as solved
1 Replies
883 Views
Hello.As a CloudKit user in my app, something came through my mind recently.How does CloudKit handle the network security? Is it end-to-end encrypted or it's made through HTTPS protocol or can an outsider sniff the network and catch the calls being made to the server?
Posted Last updated
.