Hi, I'm trying to migrate part of a project into its own Swift Package. There is no new code, just migrating code from a current local Framework to a local Swift Package.
I have this code
CachePolicy.swift
import Foundation
public class CachePolicy<Value: Codable> {
public func isValid(cacheItem: CacheItem<Value>) -> Bool { fatalError("Must override") }
}
public class CachePolicyTtl<Value: Codable>: CachePolicy<Value> {
private var ttl: TimeInterval
private var timeProvider: TimeProviderInterface
public init(ttl: TimeInterval, timeProvider: TimeProviderInterface) {
self.ttl = ttl
self.timeProvider = timeProvider
}
override public func isValid(cacheItem: CacheItem<Value>) -> Bool {
let lifeTime = timeProvider.currentTimeMillis() - cacheItem.timestamp
return lifeTime <= ttl * 1000
}
}
TimeProvider.swift
import Foundation
public protocol TimeProviderInterface {
//...
}
CacheDataSource.swift
public class InMemoryCacheDataSource<V: Codable> {
//...
private var timeProvider: TimeProviderInterface
private var cachePolicy: CachePolicy<V>
//...
public init(ttl: TimeInterval, timeProvider: TimeProviderInterface) {
self.timeProvider = timeProvider
self.cachePolicy = CachePolicyTtl(ttl: ttl, timeProvider: timeProvider)
}
On my current framework target this compiles perfectly, but the same code on the new Swift Package is returning this error
Argument type 'any TimeProviderInterface' does not conform to expected type 'TimeProviderInterface'
On this line
self.cachePolicy = CachePolicyTtl(ttl: ttl, timeProvider: timeProvider)
I don't know why is this happening.
I tried changing the timeProvider: TimeProviderInterface
to timeProvider: some TimeProviderInterface
and timeProvider: any TimeProviderInterface
but didn't work either.
What can be the problem here?
Thanks for your time.