Prevent retain cycle in Swift

195 views Asked by At

I have the following class in my project, I am wondering if this implementation will end up doing retain cycle

public final class CalendarService: AccessTokenProvider {

  internal var accessToken: Observable<AccessToken> = ... 

  private let transport: CalendarTransport

  public init(factory: ServiceTransportFactory) {
    self.transport = factory.calendarServiceTransport()
  }

  func getCalendar() -> Observable<GCalendar, NSError> {
    return self.accessToken.prefix(maxLength: 1).flatMapLatest(self.transport.getCalendar)
  }
}

my question is the self in the flatMapLatest will create a retain cycle? also what if I do this too:

func getCalendar() -> Observable<GCalendar, NSError> {
  let methodRef = self.transport.getCalendar(token:)
  return self.accessToken.prefix(maxLength: 1).flatMapLatest(methodRef)
}
0

There are 0 answers