티스토리 뷰

728x90
반응형

TCA 를 보다가 context 를  live, preview, test 로 구분하는 것을 봤다. 

 

ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"

이면 프리뷰 빌드인 지 알 수 있다고 한다.  (참고)

 

 


[ TCA 코드 ]


https://github.com/pointfreeco/swift-dependencies/blob/2ee34c93c717700eb58ab945fd0444cebe8a646f/Sources/Dependencies/DependencyValues.swift#L304

 

swift-dependencies/Sources/Dependencies/DependencyValues.swift at 2ee34c93c717700eb58ab945fd0444cebe8a646f · pointfreeco/swift-

A dependency management library inspired by SwiftUI's "environment." - pointfreeco/swift-dependencies

github.com

 

private let defaultContext: DependencyContext = {
  let environment = ProcessInfo.processInfo.environment
  var inferredContext: DependencyContext {
    if environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" {
      return .preview
    } else if _XCTIsTesting {
      return .test
    } else {
      return .live
    }
  }

 

 

https://github.com/pointfreeco/swift-composable-architecture/blob/f660a699d3cb45841bfac3dc7d76957d8ce348f4/Sources/ComposableArchitecture/Internal/Logger.swift#L38

 

private var isRunningForPreviews =
  ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"

 

 

 

 

반응형
댓글