Files
SwiftLint/Source/SwiftLintFramework/Models/SwiftVersion.swift
T
2017-07-27 14:28:40 +02:00

35 lines
823 B
Swift

//
// SwiftVersion.swift
// SwiftLint
//
// Created by Marcelo Fabri on 12/29/16.
// Copyright © 2016 Realm. All rights reserved.
//
import Foundation
import SourceKittenFramework
enum SwiftVersion {
case three
case four
static let current: SwiftVersion = {
// Allow forcing the Swift version, useful in cases where SourceKit isn't available
if let envVersion = ProcessInfo.processInfo.environment["SWIFTLINT_SWIFT_VERSION"] {
switch envVersion {
case "4":
return .four
default:
return .three
}
}
let file = File(contents: "#if swift(>=4.0)\nprint(0)\n#endif")
if !file.structure.dictionary.substructure.isEmpty {
return .four
}
return .three
}()
}