I'm new to a company and trying to understand the used generics. The setup of a model contains
var selectedChannel: Driver<Channel> { get }
@available(*, deprecated, message: "Use driver selectedChannel")
var selectedChannelValue: Channel { get }
At some point in the code selectedChannelValue.id
is used, but it shows up the warning message Use driver selectedChannel
. I understand this. Okay it still does the job but one of the previous programmers deprecated this for a reason.
How to rewrite the code-line so that I get selectedChannel.id
as the deprecation message suggests? When I use selectedChannel.id
the error message Value of type 'Driver<Channel>' (aka 'SharedSequence<DriverSharingStrategy, Channel>') has no member 'id'
appears. How to unwrap the SharedSequence
?
EDIT:
The channel
struct looks like this:
public struct Channel: Codable {
public let id: String // e.g. "1111111"
The driver
is setup in RxCocoa
as:
public typealias Driver<Element> = SharedSequence<DriverSharingStrategy, Element>
public struct DriverSharingStrategy: SharingStrategyProtocol {
public static var scheduler: SchedulerType { return SharingScheduler.make() }
public static func share<Element>(_ source: Observable<Element>) -> Observable<Element> {
return source.share(replay: 1, scope: .whileConnected)
}
}
extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingStrategy {
/// Adds `asDriver` to `SharingSequence` with `DriverSharingStrategy`.
public func asDriver() -> Driver<Element> {
return self.asSharedSequence()
}
}