iOS 응용 (swift)
[iOS - swift] device 분기 방법, 시뮬레이터 분기문 (targetEnvironment, os, arch, swift)
jake-kim
2024. 1. 27. 14:50
시뮬레이터 분기 방법
- #if targetEnvironment(simulator) 사용
#if targetEnvironment(simulator)
print("simulator")
#else
print("no simulator")
#endif
아키텍쳐, os 분기 방법
- 아키텍쳐는 arch() 사용, os는 os() 사용
- os() 안에 넣을 수 있는 것
- macOS, iOS, watchOS, tvOS, Linux, Windows, FreeBSD, Android, PS4
- arch() 안에 넣을 수 있는 것
- x86_64, arm, arm64, i386, powerpc64, powerpc64le, s390x
ex) 사용 예시
// macOS 시뮬레이터 분기
#if (arch(i386) || arch(x86_64)) && (!os(macOS))
print("Simulator")
#else
print("Device")
#endif
// iOS 시뮬레이터 분기
#if (arch(i386) || arch(x86_64)) && os(iOS)
// iOS simulator code
#endif
Swift 버전 분기 방법
- swift()사용
swift(>=2.2)
* 참고