How do I display a variable and a words at once when posting a Highscore on Facebook (swift)?

46 views Asked by At

Hi I making a basic game and I want to be able to post the users highscore on Facebook along with presets words so all the user has to do is click the post button. So basically all I need is "My highscore is xxx". i have it posting on Facebook but can't seem to put the words in with the highscore xxx.

SharetoFacebook.setInitialText("My highscore is" + finalTime.text)

where final time is a label. if i take out the "My highscore is" it will post the highscore. And if i take out the finalTime.text it will only post the words. How do I combine these together in swift?

3

There are 3 answers

0
Loanb222 On BEST ANSWER
SharetoFacebook.setInitialText("My highscore is /(finalTime.text!)")

You can add a variable to a string by writing /() with the variable name inside.

0
impression7vx On
SharetoFacebook.setInitialText("My highscore is + \(finalTime.text)")

Fairly simple syntax learning curve.

There ya go.

0
Scott B. On

You can't set the initial text for Facebook due to their terms, but you can add a link that will appear when the user presses the share to Facebook button. If you really need to set the initial text, use Twitter or email. Hope this helps!