0

So I am coding in Xcode 5 and I am working on a project that allows people to save an image that is displayed on the image view. I typed in this code...

[starImageView initWithImage:[UIImage imageNamed:@"star.jpg"]];

And then this error/warning came up...

"Expression result unused"

If you have ANY other questions about my project, let me know!

ALL answers are GREATLY appreciated!!!

Thanks!

Eric

0

2 Answers 2

1

According to Apple documentation, initWithImage is an instance method, which returns an UIImaveView object instance.

It does two things:

1: adjusts the reciever's frame (in your case starImageView) to match the size of the specified image

2: Returns another UIImageView initialized with the specified image.

Why you are getting the warning: You are not assigning the object returned by the method call. You should have something like this to get rid of this warning:

id newImageView = [starImageView initWithImage:[UIImage imageNamed:@"star.jpg"]];

(Then you will get a warning unused variable for newImageView, as you are assigning value but not using it anywhere)

Sign up to request clarification or add additional context in comments.

1 Comment

You should not call an init method on anything other than a newly-allocated instance (i.e. the result from +alloc or +allocWithZone:). And, in the vast majority of cases, the allocation and initialization should be combined into one expression (e.g. [[SomeClass alloc] init...]).
1

If starImageView has already been initialised and you are trying to set an image to imageview then you should use following statement instead.

[starImageView setImage:[UIImage imageNamed:@"star.jpg"]];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.