Skip to main content

Renamed debug identifiers: line, function, file

About 2 minSwiftArticle(s)bloghackingwithswift.comswiftswift-2.2

Renamed debug identifiers: line, function, file 관련

HACKING WITH SWIFT

What's new in Swift?

Renamed debug identifiers: line, function, file | Changes in Swift 2.2

Renamed debug identifiers: line, function, file

Available from Swift 2.2

Swift 2.1 and earlier used the "screaming snake case" symbols __FILE__, __LINE__, __COLUMN__, and __FUNCTION__, which automatically get replaced the compiler by the filename, line number, column number and function name where they appear.

From Swift 2.2, those old symbols have been replaced with #file, #line, #column and #function, which will be familiar to you if you've already used Swift 2.0's #available to check for iOS features. As the official Swift review says, it also introduced "a convention where # means invoke compiler substitution logic here."

Here’s how the debug identifiers in action from Swift 2.2 and later:

func printGreeting(name: String, repeat repeatCount: Int) {
    print("This is on line \(#line) of \(#function)")

    let upperName = name.uppercaseString

    for _ in 0 ..< repeatCount {
        print(upperName)
    }
}

printGreeting("Taylor", repeat: 5)
Other changes in Swift 2.2…
++ and -- are deprecated | Changes in Swift

++ and -- are deprecated
Traditional C-style for loops are deprecated | Changes in Swift

Traditional C-style for loops are deprecated
Comparing tuples | Changes in Swift

Comparing tuples
Tuple splat syntax is deprecated | Changes in Swift

Tuple splat syntax is deprecated
More keywords can be used as argument labels | Changes in Swift

More keywords can be used as argument labels
Variable parameters have been deprecated | Changes in Swift

Variable parameters have been deprecated
Stringified selectors are deprecated | Changes in Swift

Stringified selectors are deprecated
Compile-time Swift version checking | Changes in Swift

Compile-time Swift version checking

Download Swift 2.2 playgroundopen in new window


이찬희 (MarkiiimarK)
Never Stop Learning.