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

brycecampbell
2,112 PointsObjective-C Dynamic Typing Code Challenge
Use NSLog to print out the value of the variable 'thing'. The output should look like: "thing = 4".
4 Answers

John W
21,558 PointsNSLog, as you know, outputs the string to the console/log. To output the string Hello World
, you do NSLog(@"Hello World");
You can dynamically replace part of it using format strings, which are preceded with the percent symbol. To output the string Our number is #
, where # should be replaced by some number from a variable variable
, you do
NSLog(@"Our number is %d", variable);
If variable
has the value 5, %d would be replaced by the number 5, the end result is "Our number is 5"
(%d is used for integer, other options include %f for float, %@ for Objective-C object, %c for a single character, etc)

Jay Mayu
6,805 Points3 years of development with Java and JavaScript makes me forget the "@" in front of string. Thanks clared my quiz :)

Bruno Ishii de Souza
Courses Plus Student 3,481 PointsI am having the same problem! I am putting the code like this:
id thing = nil;
thing = [[NSNumber alloc] initWithInt:4];
NSLog = (@"thing = %@", thing);
and the error is:
Bummer! Compiler error! Make sure you are passing an 'NSString' to NSLog with the correct format, and check your syntax!
Somebody help!!!

John W
21,558 PointsTake out the = after NSLog

Bruno Ishii de Souza
Courses Plus Student 3,481 Pointscan't believe I did that hahahaha thanks!

brycecampbell
2,112 Pointsso far i did the Dynamic Typing Code Challenge. I completed task 1 and task 2 but having trouble with task 3 where i have Use NSLog to print out the value of the variable 'thing'. The output should look like: "thing = 4".
need help please------>@

brycecampbell
2,112 Pointswhen i print out NSLog(@" thing is %d", thing) it says "not the correct input to NSLog"

John W
21,558 PointsClose! The question asks for an output of the format thing = #
, what you had there would print thing is #
John W
21,558 PointsJohn W
21,558 PointsAnd what have you tried so far?