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
Tom Coomer
1,331 PointsIf statements in xcode
In my app, when the user shakes the device a word from an array is shown in a label (very similar to the crystal ball app).
How would I then make a message appear in another label if a certain word appears.
E.G. label 1 will say "treehouse" label 2 will say "welcome" but only if label 1 says those specific words.
Hope this is clear and understandable. Thanks
4 Answers
Marshall Huss
3,504 PointsOne way of doing this would be to check the text of label1 using the -isEqualToString: method after it's been set, and then set label2 accordingly.
if ([label1.text isEqualToString:@"treehouse"]) {
label2.text = @"welcome";
}
Tom Coomer
1,331 PointsWhere does the code need to go?
Marshall Huss
3,504 PointsI would put it in the shake method, after label1 has been set.
Tom Coomer
1,331 PointsOk. Ill try it now. Thanks.