Last active
August 29, 2015 14:23
-
-
Save austinzheng/08385dd81cf0b8845ce1 to your computer and use it in GitHub Desktop.
Weird stuff with free function labels in Xcode 7.0 beta 2...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// Running on Xcode 7.0 beta (7A121l) | |
// All running in a playground | |
// Open console (View -> Debug Area -> Show Debug Area) | |
// Define a non-generic free fn taking 1 arg | |
func notGeneric(x: String) { | |
print("notGeneric called") | |
} | |
notGeneric("hello world") // works | |
//notGeneric("hello world", false) // doesn't compile | |
//notGeneric("hello world", foo: false) // doesn't compile | |
// Now, define a generic free fn taking 1 arg | |
func thisFnIsGeneric<T>(x: T) { | |
print("thisFnIsGeneric called") | |
} | |
thisFnIsGeneric("hello world") // works | |
thisFnIsGeneric("hello world", true) // works | |
thisFnIsGeneric(foo: "hello", bar: "world") // works | |
// Trying similar things with 'print()', which has an optional second argument. | |
// All 3 work as expected; they call the built-in 'print()' function with the correct newline behavior | |
//print("test") | |
//print("test", appendNewline: true) | |
//print("test", appendNewline: false) | |
// All of these compile and work as if they were calls to the built-in 'print()' with the correct label names | |
// Fun fact: if you try running this code as an actual project, these print out as tuples instead. | |
print("test1", appendNewLine: false) | |
print(foo: "test2", BAAARRRRR: true) | |
print("test3", false) | |
// Trying something else... | |
func print<T>(argument: T, appendNEWLINE: Bool) { | |
print("Overloaded 'print' called") | |
} | |
// This calls the overloaded version of 'print' defined above | |
print("hello", appendNEWLINE: true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment