Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-24-2011, 01:38 PM   #1 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default Slick's Guide To Troubleshooting, Problem Solving, Error Codes

Coming Soon. Mostly a concept right now, I don't have enough content yet, so I'll fill these out as I find/make examples.

Compiler Warnings & Errors
Build-and-Analyze Messages
Crash Messages
Problem Solving Techniques
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 03-24-2011, 01:40 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

WARNINGS
Warnings should be fixed, but you will not be prevented from running your app. Your app may run just fine, or your app may crash. Depends upon the nature of the warning. Rule of thumb: fix them.

Unused Variable

Brief: You defined a variable, but then you didn't do anything with it. The variable is unused.

Code example:

Code:
- (void)anyMethod
{
   NSString *aVariable = @"Hey There";  // warning: unused variable 'aVariable'
}
Consequences:
Nothing, really. This is a helpful message to let you know that you went to the effort to declare something, but then you didn't do anything with it.

Possible Solutions:
1. Do something with the variable somehow. Ex:
Code:
[[self aTextField] setText:aVariable];
2. Delete or comment out the offending code


May Not Respond

Brief: You are calling a method on a particular class. The compiler is not finding that method declared (in .h file) for that class. The compiler does not know if the class implements that method.

Code example:

Code:
- (void)anyMethod
{
   [self doThatThingYouDo];  // warning: 'RootViewController' may not respond to '-doThatThingYouDo'
}
Consequences:
Depends on whether the method actually is implemented in .m file. If it is, your app will work just fine. If it isn't, your app will crash when this line is executed.

Possible Solutions:
1. Verify that you are calling the correct kind of object. The warning message tells you which class type is being called - RootViewController. Make sure that is the correct target.
2. Verify that the method is declared in the .h file. In this case:
Code:
- (void)doThatThingYouDo;
3. In some situations, the compiler may not know what kind of object you are dealing with (the type is "id"). You can help the compiler by typing the object.
Code:
[(NSString *)[theArray objectAtIndex:0] length];
In this case, we are telling the compiler to assume that the item in the array is a string. Now it knows that length is a valid method. IMPORTANT: This does not force the objects in the array to become strings. If you have views in the array instead, that will be bad at run time.


Local Declaration of Variable Hides Instance Variable

Brief: You have defined an instance variable, AND defined a local variable with the same name. So you're not using your instance variable.

Code example:

Code:
// .h
@interface RootViewController : UIViewController 
{
   NSString *aVariable;
}

// .m
- (void)anyMethod
{
   NSString *aVariable = @"Hey There";  // warning: local declaration of 'aVariable' hides instance variable
   aVariable = @"Oops";
}
Consequences:
You are only messing with the local variable, not the instance variable. It's as if your instance variable doesn't exist. So if we log this variable at a later time:
Code:
NSLog(@"aVariable is: %@", aVariable);
...
aVariable is: (null)  // Uh, thought it should be "Oops".  Oops!
Possible Solutions:
1. Use a different variable name:
Code:
NSString *notThatVariable = @"Hey There";
2. Don't re-declare the variable:
Code:
aVariable = @"Hey There";
IMPORTANT: Messing with instance variables in this way is very dangerous. See the properties link in my signature for a better approach.







ERRORS
Errors must be fixed. You will not be able to run your app until they are fixed.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.

Last edited by BrianSlick; 03-24-2011 at 02:27 PM.
BrianSlick is offline   Reply With Quote
Old 03-24-2011, 01:40 PM   #3 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Space reserved: Build-and-Analyze Messages
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 03-24-2011, 01:41 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Space reserved: Crash Messages
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 03-24-2011, 01:42 PM   #5 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Space reserved: Problem Solving Techniques
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 04-18-2011, 06:33 PM   #6 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 152
mrtubby is on a distinguished road
Default

fixing warning was super helpful!! thanks for taking the time to make it!!
mrtubby is offline   Reply With Quote
Old 08-24-2011, 05:38 PM   #7 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 63
Gianmarco Odirzzi is on a distinguished road
Default

Thanks for that! Nice idea!
If you add console crash errors to your guide would be great, as sometimes it is difficult to find errors in the code if the compiler does not return any warnings/errors!
Gianmarco Odirzzi is offline   Reply With Quote
Old 05-10-2012, 04:39 PM   #8 (permalink)
User Interface expert
 
_Mac's Avatar
 
Join Date: May 2009
Location: Sweden
Posts: 141
_Mac is on a distinguished road
Question

@BrianSlick
Really good post idea. Maybe you should invite others to contribute with there own warnings / errors AND there solutions to them?
__________________
-- Happy Coding
_Mac is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 369
12 members and 357 guests
condor304, dansparrow, Domele, dre, dreamdash3, ilmman, LezB44, michelle, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:35 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0