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

Resizing 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

Jeremy Davis

Assuming the code you posted above is a direct copy from the challenge, you should be using '==' when comparing the caption length to 0.

Ive tried it both ways, and it isnt a direct copy I just typed it out really quick

Thanks!

We 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.

so it should be " if (self.image !=nil && [self.image length] !=0) " ?

Yes 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.

Thanks! 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!

You'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.

hello 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){

}

Place the rest of the rest of the code for the function in between the if statement's curly braces.

wow cant believe i missed that thanks

You're welcome