본문으로 바로가기

[Swift] NSDate 시물레이터 구분 방법

category Mobile Application/iOS 2016. 4. 30. 16:20
import UIKit

struct Platform {
    static let isSimulator: Bool = {
        var isSim = false
        #if arch(i386) || arch(x86_64)
            isSim = true
        #endif
        return isSim
    }()
}


func timeZoneLocalDate() -> NSDate {
    if Platform.isSimulator {
        print("a")
        // Do one thing
        let timeZone: NSTimeZone = NSTimeZone.localTimeZone()
        let currentGMTOffset: Int = timeZone.secondsFromGMT
        return NSDate().dateByAddingTimeInterval(NSTimeInterval(currentGMTOffset))

    }
        print("b")
    return NSDate()
}

참고 : http://stackoverflow.com/questions/24869481/detect-if-app-is-being-built-for-device-or-simulator-in-swift