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
Jeremy Davis
Courses Plus Student 5,711 PointsResizing Images Code Challenge (Task 1)
I have tried every variation and have done as much research as I can. I am really thinking this could be the code engine.
Here is the question : In this Latergram app, we only want to upload an image if the 'image' and 'caption' properties of the view controller below are set. In the 'upload' method, add a check to make sure that both properties have values before executing the block of code. Note: 'image' is a UIImage and 'caption' is an NSString.
In my code I have if(self.image == nil && [self.caption length] = 0) {}
Help would be great! Thanks in advance!
4 Answers
David Kaneshiro Jr.
29,247 PointsAssuming the code you posted above is a direct copy from the challenge, you should be using '==' when comparing the caption length to 0.
Jeremy Davis
Courses Plus Student 5,711 Pointsso it should be " if (self.image !=nil && [self.image length] !=0) " ?
David Kaneshiro Jr.
29,247 PointsYes and make sure that the rest of the code that was given to us in the challeng is enclosed within the if statement's body.
Jeremy Davis
Courses Plus Student 5,711 PointsThanks! I just wasnt reading the NOT part correctly. It makes sense now. Instead of seeing if it is set to nil and running the code in the else statement making sure that it is NOT empty and running the code within the if statement it is the same thing. I appreciate the help!
David Kaneshiro Jr.
29,247 PointsYou're welcome. Outside of the code challenge your way would have worked. It's just a quirk of the code challenges to expect the answer to be written a certain way.
Kai Aldag
Courses Plus Student 13,560 Pointshello guys in on the same thing but i cant seem to get it here my code : - (IBAction)upload { if (self.image !=nil && [self.caption length] !=0){
}
David Kaneshiro Jr.
29,247 PointsPlace the rest of the rest of the code for the function in between the if statement's curly braces.
Kai Aldag
Courses Plus Student 13,560 Pointswow cant believe i missed that thanks
David Kaneshiro Jr.
29,247 PointsYou're welcome
Jeremy Davis
Courses Plus Student 5,711 PointsJeremy Davis
Courses Plus Student 5,711 PointsIve tried it both ways, and it isnt a direct copy I just typed it out really quick
Thanks!
David Kaneshiro Jr.
29,247 PointsDavid Kaneshiro Jr.
29,247 PointsWe have to change the 'if' statement to test that the image is not set to nil and the caption length is not set to 0.