Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Need to append quotesLabel.text to nameLabel.text to "from Carmel Heart Media." How?

to pass within SLServiceTypeFacebook

here:

var facebookSheet:SLComposeViewController = SLComposeViewController (forServiceType:SLServiceTypeFacebook)

            facebookSheet.setInitialText quotesLabel.text

(That will post a random quote to Facebook. But, how do I add two more items to also post to Facebook?)

I've tried all kinds of things. I feel stupid.

Oh, and this is in Swift.

3 Answers

While I'm not sure if this works, how I'd expect it to work is using + to combine strings

let string = "Hello " + name + ", how are you doing"

http://i.imgur.com/rcZ49sP.png

  1. At the top of View Controller, I put this:

var messageString:String = " (Sent via the XYZ app from Carmel Heart Media.)"

  1. Further down in the doc, under the social media integration section, I did this:

var postingString = (quotesLabel.text)! + messageString

facebookSheet.setInitialText (postingString)

  1. Problem is that now, I want it to have (quotesLabel.text) + (nameLabel.text) + messageString

and it does not seem to work to combine two text fields together with the messageString.

(See, I want whatever is appearing in the label at that time to be sent to FB or Twitter, and the content of the labels will vary. )

Ok, is this what you're trying to do

http://i.imgur.com/rcZ49sP.png

Ezekiel, thanks for all your hard work in trying to help me! It has taken me a little over a week now to finally figure out how to do this- It's like this:

var postingString = (quotesLabel.text)! + quotebyString + (nameLabel.text)! + messageString

facebookSheet.setInitialText (postingString)

I have text that randomly shows up in a quotes label and that randomly shows up in a name label. So, I had to set both of them up as outlets with actions so that words could pass through them.

The finished result looks like this:

http://imgur.com/vVddqEs

(It's a religious app.)

The quote came off the quote label, name off the name label and plus the message. It was really hard for me to figure it all out!

BUT now if anyone wants to post different bits and pieces within your app to Facebook using Swift, here is how. :)