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
Hamza Ansari
1,014 PointsHow do I re-write this code into Objective-C?
It's right here:
func addVote(countOption1 :String) ->String {
let result = countOption1 + countOption1
return result
}
Unfortunately I don't know how to convert Parse.com's Starter Project file into Swift, since it's formatted in Objective-C. This is the only code I've added (so far) to my starter project but I need to write it in Objective-C to fit the template. The app I'm working on is supposed to be a bunch of different polls where users can vote for different options and view the results of the poll after they've taken them.
1 Answer
Christopher Hall
9,052 PointsHere is the equivalent function in Objective C:
- (NSString *) addVote:(NSString *) countOption1 {
NSString *result = [countOption1 stringByAppendingString:countOption1];
return result;
}
In this case, the first NSString in parentheses would be the type of object being returned from the function. addVote is the name of the function, with one parameter, also of type NSString. Since you seem to be adding them together and returning them in the function, the stringByAppendingString function call will get you the results you seek.