0

Im getting the warning "Expression result unused".

enter image description here

I dont know why this is showing. It is working correctly. Showing the right title and the images so why the warnings? what can i do to fix these warnings?

Thank you all for the help!

----------------------------------------------------- Edit 1

WHen i write it like this i get no warning.

   tabBarItem1 = [tabBarItem1 initWithTitle:@"Matcher Idag" image:[UIImage imageNamed:@"games-2.png"] selectedImage:[UIImage imageNamed:@"games-2.png"]];

BUT when i go to Product -> Analyze then it says: " Value stored to tabBarItem1 is never used

Timo Cengiz
  • 3,367
  • 4
  • 23
  • 45
  • Maybe because the selectedImage is the same as the regular image? – RegularExpression Dec 08 '14 at 01:14
  • 1
    BTW, don't post PICTURES of code. Copy/paste the code into your post and use code formatting. That way it's readable, and people can copy/paste the code if they want to make suggestions. – Duncan C Dec 08 '14 at 01:20
  • True, thank you for taking your time and explaining things to me. Very helpful @DuncanC You seem like you know your stuff. If you by any chance have some time over and look over this post i made if you have any ideas it would be very kind of you http://stackoverflow.com/questions/27347937/changing-position-of-a-uilabel-for-a-custom-uitableviewcell – Timo Cengiz Dec 08 '14 at 01:23

1 Answers1

2

That code is very, very wrong.

Init methods return an object. You're supposed to use it, because sometimes the init method returns a different object than the one you started with.

You almost always use alloc and init together in a pair, e.g.:

tabBarItem1 = [[tabBarItem alloc] initWithTitle: @"title" 
  image: myImage
  selectedImage: anotherImage];

If you're not an experienced Objective-C developer and you're calling alloc and init separately, you are making a mistake. I can count on the fingers of 1 hand the number of times I've used init where it wasn't in the alloc/init pattern I showed above

The code you posted doesn't make a lot of sense. You shouldn't be sending init messages to objects that are already part of your tab bar. That's a no-no. Those objects have already been initialized, and you are only supposed to send one init message to an object in it's lifetime. What you are doing is going to cause problems. Big problems.

Instead you should use the title and image properties:

tableBarItem1.title = @"new title";
tableBarItem1.image  = myImage;
tableBarItem1.selectedImage  = mySelectedImage;
Duncan C
  • 128,072
  • 22
  • 173
  • 272