Swift NSString function syntax usage
I have a basic question about swift function calling syntax. I have read documentation but not able to figure it out. So decided to put a query over here.
A piece of code i wrote
var string1 = NSString().stringByAppendingString("First string") var string2 = NSString.stringByAppendingString("Second string") println(string1) println(string2)
Both string have same function calling but return type is different. And only difference here is
(). I got out put like
Question is why its not giving a warning/error. Is it that
var string2 holds method body of
stringByAppendingString? Whats going on, New swift developer like me can easily make a this type of typo mistake and not able to figure out.
Can you please explain why its not return value?
Solutions Collect From Internet About “Swift NSString function syntax usage”
This happens because swift methods are curried functions (you can find detailed explanation in Ole Begemann’s post).
So what you actually got in the following line:
var string2 = NSString.stringByAppendingString("Second string")
is a function that takes a string as parameter and returns the result of
You can check that by calling string2 as an ordinary function:
string2("123") // Prints: "Second string123"
- Using Dictation – iOS 6 – DidStart?
- Cannot open Xcode project on a new Mac
- bridgeToObjectiveC and makeObjectsPerformSelector in Swift beta 5
- How do I segue to 2 views based on a Segmented Control and an Add button?
- HighChart Libraries for Android and IOS
- Why do the pages blink/flicker after transitions in my jQuery Mobile PhoneGap app on iOS?
- Install xCode 3.2.3 w/ iPhone SDK 4, get “Base SDK missing”, can't see other SDKs
- xcode – load localized images with the same name, not using nslozalicedstring
- What's the Swift equivalent of Objective-C's “#ifdef __IPHONE_11_0”?
- CGAffineTransformInvert: singular matrix
- “collect2: ld returned 1 exit status” Error Iphone SDK. Please help me
- Swift 2 JSON POST request
- Chained expressions to perform calculations in Core Data
- How to reduce the size of my iPhone application?
- How to get date and time of selected time zone from uipicker in Xcode