Does the Swift compiler compile unused functions or does it ignore them?
Unused functions do make your program larger.
This is pretty easy to test. Created a new Swift application as a Single View Application (iOS). In the generated ViewController.swift, add a function. Do a build (Command-B) and check the product's build folder. This is usually:
~/Library/Developer/Xcode/DerivedData/
<AppName>-<IDString>/Build/Products/Debug-iphoneos/
<AppName>.app/
Check the file size of <AppName>.
Comment out the function and do a build again. The file size will be smaller.
I created an app called SwiftSandbox and added this:
func doSomething() -> NSString {
var v: NSMutableString = NSMutableString(string: "MyString is Funny")
v.replaceCharactersInRange(NSMakeRange(3, 3), withString: "World")
return v
}
When building with this function, I saw this in bash:
-rwxr-xr-x 1 test staff 213648 Apr 27 11:33 SwiftSandbox*
With the function commented out:
-rwxr-xr-x 1 test staff 142992 Apr 27 11:33 SwiftSandbox*
Note that I didn't change any optimization settings in Xcode so I can't be sure what effect that would have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With