Try the search, it's linked to some great forums

Thursday, June 30, 2011

warning: implicit declaration of function

This bastard is;
......../Classes/TemplateUIViewViewController.m:103: warning: implicit declaration of function 'UIGraphicGetCurrentContext'

And how to fix him ???

Integer without a cast

This error;
...../Classes/PostCard.m:42: warning: assignment makes pointer from integer without a cast


This appears when???

A typical (id)init method

This example shows a;
- (id)init {
    // Set self's frame to encompass the image
    if (self = [self initWithFrame:frame]) {
        placardImage = image;
        [self setupNextDisplayString];
    }
    return self;
}

The (id) allows for ANY object, and it must return it's self

Country GDPs

Wednesday, June 29, 2011

warning: Unable to read symbols for ....... (file not found)

Console error;
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 (8J2)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).

What do YOU mean?

NSZombie memory tracking

Use NSZombie for tracking memory errors.  You use it by setting the access
Go to Project -> Edit Active Executable 
Click Arguments 
Click + in the "Variables to be set in the environment" section 
Enter NSZombieEnabled in the Name column 
YES in the Value column. 
Make sure the checkmark for the NSZombieEnabled entry is checked.

This will allow you to see retain counts & deallocated objects

EXC_BAD_ACCESS error

This error message from the console;
Program received signal:  “EXC_BAD_ACCESS”.

is typically thrown as the result of an illegal memory access, like trying to access a deallocated object or sumthin. Try using the NSZombieEnabled feature.  This will tell you which memory address is deallocated, actually where it was set.
-[PostCard postCardLeft]: unrecognized selector sent to instance 0x347c70

You can then use the Debugger to track it down

[[[      alloc]   init]   retain] can be used  sometimes to keep a variable around

warning: 'PostCardsViewController' may not respond to .......

This warning is displayed at compile time;
/Users/chris/...../PostCardsViewController.m:461: warning: 'PostCardsViewController' may not respond to '-transitionFromView:toView:.......'

This warning is often displayed if the method you are calling has it's definition below the area it's called.  You can either move the method above or more properly declare that method at the top of the .m file as a @private property.


unrecognized selector sent to instance 0x3373c0

This error message from the console;
unrecognized selector sent to instance 0x3373c0

means that ????

Xcode shortcut keys

Xcode shortcut keys

Tuesday, June 28, 2011

random method

A simple random number generator method
- (float)randomNumber    // -1.000 to +1.000
{
    int y = (random() % 2000) - 1000;      
    float randomNumber = y / 1000.0;
    return randomNumber;
}

NSString formatting

The following formatting strings are commonly used
%2.3f   floating point number 2 digits, 3 decimal places
%d       integer number
%@     object descriptor

General format for NSString / NSLog message;
NSLog(@"This is the message along with it's variable %@", myObject);
NSString *leftPostCardName = [NSString stringWithFormat:@"image%d.jpg",(i+1)]; 
UIImage *leftPhoto = [UIImage imageNamed:(@"%@", leftPostCardName)];                       
 

And try this for converting from string to number
NSString *myString = (string initialization here)
float stringFloat = [myString floatValue];  

Random html poste

Here's a infographic look at the science basics of Japan's earthquake and tsunamis.
Source:LiveScience 

Monday, June 27, 2011

random number generator

Use this.  y is an integer random number. x is the modulo (remainder of y/100) divided by 1000. Or a number between 0.000 and 0.100.

    int y = (random());      
    float x = (y % 100) / 1000.0;
    NSLog(@"random() is %d", y);
    NSLog(@"modulo is %2.3f", x);

Use this, to create a number between -1.000 to +1.000;

    int y = (random() % 2000) - 1000;       
    float x = y / 1000.0;
    NSLog(@"random() is %d", y);
    NSLog(@"modulo is %2.3f", x);


Apparently, this is not truly random, because the number series is always identical.  Good enough for many things.
Other functions to look at are arc4random() or srand(time(NULL)); which requires seeding. 

Saturday, June 25, 2011

Posting an alert message for low memory warnings

The following code can be used to create an alert message if the application receives a system memory warning.  This method is included in the AppDelegate .m file.

- (void)didReceiveMemoryWarning {
    // Displays an alert message if there is a memory warning
    [super didReceiveMemoryWarning];

//    NSError *error;
//    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);            //error log message
    UIAlertView *memoryAlert = [[UIAlertView alloc] initWithTitle:@"Low Memory Warning"
            message:@"Close some programs!"
            delegate:nil   
            cancelButtonTitle:@"Cancel"
            otherButtonTitles:nil];
    [memoryAlert show];
    [memoryAlert release];   
   
    // Release any cached data, images, etc that aren't in use.
}

The alert message could also be used to log an error code or message.

Tuesday, June 21, 2011

Adding a photo (jpg) to a UIView

This technique is used to load a jpg or png file located in the resources directory into a UIView where all sorts of fun can be had;
//Gets photo name
    UIImage *rightPhoto = [UIImage imageNamed:@"image6.jpg"];
   
 //Configure and place image
    UIImageView *rightImage = [[UIImageView alloc] init];
    CGRect rightFrame = CGRectMake(800.0, 390.0, 200.0, 150.0);
    rightImage.frame = rightFrame;
    rightImage.image = rightPhoto;
   
 //Apply the Images to the view
    UIView *rightPostCard = [[UIView alloc] init];
    [rightPostCard addSubview:rightImage];
    [self.view addSubview:rightPostCard];
    [rightImage release];

Simple Gestures - Swipe

Xcode has a great series of multiTouch gestures.  This snippet creates the most simple swipe;

Add the protocol delegate to the View Controller's .h header file;

     UIGestureRecognizerDelegate

Add the following code to the viewDidLoad in .m file for each gesture defined;
    UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc]
                                         initWithTarget:self action:@selector(handleSwipe:)];
    [self.postCard addGestureRecognizer:swipeRecognizer];
    [swipeRecognizer release];


Create the handleSwipe method like;
- (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer
{   
    [self transformMoveNScale];   
}

Monday, June 20, 2011

Mac screen capture keystrokes

Shft-Cntrl-Cmd-4 allows you to cut & paste an area of the screen

Base SDK Missing

Often when loading up new code from somewhere, you might get the following error;
Base SDK Missing

Goto Project - Base Project Settings - General tab and change the Base SDK to the following;






Then save & reopen the Project.  Should compile & run just fine now.

This is where to go in xcode 4.1.xxx







This is where to go in Xcode 4.3.xxx