Post not yet marked as solved
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
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?
Post not yet marked as solved
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?
Post not yet marked as solved
Hello.I have huge difficulties on understanding the general CloudKit billing this - but I'll go by parts explaining everything in order to get some precious help.I'm currently developing an app, which is right now on external testing through TestFlight. On a general side, the app is below the free quota Apple offers but not the Asset Transfer quota, which is free up to 2GB.Question 1:Am I going to be billed for the extra Asset Transfer even during TestFlight? Note that the app isn't in the AppStore yet.Question 2:Right now, I am at 25GB of asset transfer, and since Apple allows 2GB, I'm 23GB in debt right? Making some easy calculations, Apple bills $0,10 per extra GB, so I'll have to pay 0,10 * 23 = $2.3.What will happen now? When we reach the 2GB mark, does Apple deny the service access and we have to call them and buy in advance extra transfer space, OR does Apple allow the transfer to go on and on until the end of the month? If so, how do they charge us? Through our Apple account linked credit card?I'm sorry to as this so straight forward, but I cannot find anywhere else an answer to this doubts I'm having.And where should I contact Apple to release more space on my CloudKit quota?Thank you very much, looking forward to get some help here.