How to convert NSData to NSString and back
NSString* myString;
myString = [[NSString alloc] initWithData:nsdata encoding:NSASCIIStringEncoding];
NSData* nsdata;
nsdata = [myString dataUsingEncoding: NSASCIIStringEncoding];
How to get the class type of an object?
Say you have a class of type “Car” and you need to check if an object you have at runtime is of that type:
if ([myRuntimeObject isKindOfClass:[Car class]]){
//do something....
}
For all you Jewish Folks: Kotel Notes iPhone App Released!
iPhone : famous crash – “this class is not key value coding-compliant for the key”…
If you came across this error :
*** Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key myLabel.’
(replace myLabel with any other name you may have used)
In most cases the cause for this error is a renaming of a UI property such as an IBoutlet in Xcode without updating the binding in Interface Builder. When you come across this thing, do the following:
- Look for the controller that holds your property (in the case of the sample above : myLabel)
- Open the controller’s corresponding Nib file in Interface Builder
- Reconnect your UI control (in the case of the sample : a UILabel) to the new property name.
iPhone : warning: no ‘-renderInContext:’ method found – solution
There is a simple solution to this pesky warning:
- Add the following to your .h file :
#import <QuartzCore/QuartzCore.h>
- You may also need to add “CoreGraphics.framework” to your project, if its not already there.
iPhone : warning: no ‘-renderinInContext’ method found
If you are trying to do this:
[myView.layer renderInContext:myCtx];
and get the this warning :
warning: no '-renderinInContext' method found
Simply add the following to the top of your .h file:
#import <QuartzCore/QuartzCore.h>
iPhone : Simple method for converting radians to degrees
This is a simple method that you can use to throw degrees in and get radians out.
// put this static method somewhere convenient
+ (float)degreesToRadians:(float)degrees{
return degrees / 57.2958;
}
iPhone : How to rotate an image
Say you have an UIImageView called : myImage, and you want to rotate it by 35 deg around its center point.
This can be achieved like so:
// first we set the rotation axis. (This is relevant for all transformation actions)
myImage.center = CGPointMake(0, 0);
// then we apply the transform. Quartz uses radians, so we need to pass radian value and not degrees.
// check out my next post on converting radians to degrees...
myImage.transform = CGAffineTransformMakeRotation([degreesToRadians:imageRotationFix]);

