Silver VS Swift

Hey,
I am new here and I overcome this problem, I am trying to split a string, so I googled some swift solution and I found this
var fullNameArr = split(fullName) {$0 == " "}
what is not working in Silver at all, because I have to write it like this
var splitted = content.Split(" ") what is C#
I thought that I can use Swift programming language in VS when I have Silver, but this syntax is different. So maybe I just do not understand what Silver actually is.

thank you

split() is a function in the base library, not a part of the a Swift language syntax, per se. We’re working on expanding the base library to cover most of the common APIs such as this one eventually, but it’s not quite there yet as we’ve been foremost focused on the compiler itself. The silver base library will also be open source on github, so Silver users can contribute and help expand it for full coverage.

content.Split() is not C#, it’s a method exposed by the .NET Steing class, available tegardless of the language used. So if course it’s available in Swift as well. It’so important to distinguish between C# (which is a language,must like Swift is) and .NET (which is a platform and set if types that expose certain APIs — regardless of language used).

Hope this helps to clarify things.

okay got it, that means the split is not yet done. and thanks for the explanation

edit
does this mean that I cannot use toInt because of the same reason? I am trying to convert string to int but failing hard

probably. is toInt() a base library API function or a member on Swift.String? Int32.Parse() should work n the mean time.

cool, thanks, I have one more issue that I do not understand at the moment, I think is because how String works in Silver, I have function

public func inputNumberAndOperation(number : Int, oper: String)

and I am calling it

myCalc.inputNumberAndOperation(10,"someInput")

and I am getting this

(E316) No overloaded method "inputNumberAndOperation" with these parameters on type "Calculator!"

I tried to call it just with the number, number is fine, so the String is problem but I have no idea how to fix this.
thanks.

is this func inside a class? if so you need to call it as

myCalc.inputNumberAndOperation(10, oper: "someInput")

or declare it as

public func inputNumberAndOperation(number : Int, _ oper: String)

if you don’t want it to require the prefix on the second parameter. This is basic Swift func declaration logic, same in Silver and Apple’s Swift, FTR.

thanks a lot, I was looking at this documentation https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html

instead of this one
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Methods.html

it is imho very confusing and inconsistent, yeah. still trips me up all the time, too :frowning:

Is there any chance we can have a compiler switch or pragma which implies an underscore prefix before all such params?

For people who haven’t used Objective C (where is might make sense), that design choice is bewildering.

i think that would probably make it even more confusing, because then you can’t even know what to expect just from looking at the code even if you are fully aware of how Swift does this. But i’ll bring it up for consideration.

We can/should certainly improve error message to make this more clear when you run into this case.

That wasn’t a terribly detailed proposal on my part. What I’m thinking is a switch that makes parameter name use a choice for user of the function instead of the definer. So in that case external names are always available (be it through a default or explicit external name) and are always optional. The user can then pass parameters by position or name as they see fit. There would have to be a rule when interleaving them, such as named parameters can only come after positional parameters or named parameters are not counted when determining a positional parameter’s index.

But what if the position alone is not unique enough? you could have two methods that only differ in the prefix for the second parameter.