Get build date and time in Swift

前端 未结 3 489
温柔的废话
温柔的废话 2020-12-17 16:21

I\'m using __DATE__ and __TIME__ in Objective-C to get the build date and time of my app. I can\'t find a way to get this information in Swift. I

3条回答
  •  爱一瞬间的悲伤
    2020-12-17 17:04

    Swift 5 version of Alain T's answer:

    var buildDate: Date {
        if let infoPath = Bundle.main.path(forResource: "Info", ofType: "plist"),
            let infoAttr = try? FileManager.default.attributesOfItem(atPath: infoPath),
            let infoDate = infoAttr[.modificationDate] as? Date {
            return infoDate
        }
        return Date()
    }
    

提交回复
热议问题