1

While researching the String Structure Reference from Apple (String Structure Reference)

There are initializer methods that accepts Int parameters such as:

init(stringInterpolationSegment expr: Int)

I attempted by writing the code below to learn how to use it plus learn the difference between pass by reference vs. pass by value but can't get it to work using the following:

struct Soho {
    var myCountry = "America"
     init(stringInterpolationSegment expr: Int){

     }

}

How should swift code be structured in order to use this string initializer?

0

1 Answer 1

2

From https://developer.apple.com/reference/swift/string/1539185-init, Apple says:

Creates a string containing the given value’s textual representation.

Do not call this initializer directly. It is used by the compiler when interpreting string interpolations.

(emphasis mine)

And they show you an example in https://developer.apple.com/reference/swift/stringinterpolationconvertible, where we see that indeed we should use String interpolation with "\()".

Sign up to request clarification or add additional context in comments.

2 Comments

Appreciative. The Apple reference I have linked to is somewhat different from the Apple reference you've linked to. I was able to obtain my link by doing a Google search on "string reference apple". How do I reach the Apple reference you have? Maybe just me but yours looks more understandable to read and search through. @Eric D
developer.apple.com/reference/swift is a new documentation system they've implemented very recently. I believe it will soon be indexed and prioritized properly by Google. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.