29/06/10

Debugging with NSLog: format specifiers

Filed under: iPhone Dev SDK by Tesh @ 15:33

NSLog is a Foundation kit function for printing debug statements to the console. It’s very helpful to debug your applications, but sometimes you need to print some special kind of data. These are its format specifiers:

%@ Object
%d, %i signed int
%u unsigned int
%f float/double
%x, %X hexadecimal int
%o octal int
%zu size_t
%p pointer
%e float/double (in scientific notation)
%g float/double (as %f or %e, depending on value)
%s C string (bytes)
%S C string (unichar)
%.*s Pascal string (requires two arguments, pass pstr[0] as the first, pstr+1 as the second)
%c character
%C unichar
%lld long long
%llu unsigned long long
%Lf long double

23/06/10

UIImage negative color effect

Filed under: iPhone Dev SDK by Tesh @ 09:10

It’s simple to convert an UIImage to his negative image. Only use this code:


UIGraphicsBeginImageContext(renderImage.size);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
[renderImage drawInRect:CGRectMake(0, 0, renderImage.size.width, renderImage.size.height)];
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference);
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor);
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, renderImage.size.width, renderImage.size.height));
renderImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

10/11/09

CGPoint and other CG variable can store in NSArray

Filed under: iPhone Dev SDK by Tesh @ 15:45

Often is possible that we need to store CG variables in NSArray. You can follow this code to do it.

For example we need to store CGPoints.


NSArray *points = [NSArray arrayWithObjects:
[NSValue valueWithCGPoint:CGPointMake(5.5, 8.3)],
[NSValue valueWithCGPoint:CGPointMake(11.9, 8.5)],
nil];

And when we need to get these points, for example the first point


NSValue *val = [points objectAtIndex:0];
CGPoint p = [val CGPointValue];

19/10/09

About EXEC_BAD_ACCESS error

Filed under: iPhone Dev SDK by Marc @ 09:08

I know that It’s been so far since my last post, but I have been very very very busy since then, but I’m here again, this time to talk about the EXEC_BAD_ACCESS error.

This kind of error is hard to debug, it happens when a message is sent to a released object, but the Xcode debugger doesn’t give any kind of information about which is the released object, because it is already released and it isn’t allocated in memory anymore, so the debugger doesn’t know it’s structure and it only has a pointer to an “empty” memory address. As the application can crash at anytime before the object is released it seems to be quite aleatory and sometimes hard to reproduce and trace.

More about this post

16/09/09

iPhone icon without shine & gloss effect

Filed under: iPhone Dev SDK by Tesh @ 14:47

The default icon, in a iPhone projects, has a shine and gloss effect by default. If you want create your effects in the icon image, you must disable this effect. To do it, you need to add a new property in the info.plist file. The key of this property is UIPrerenderedIcon and it needs to be set to YES. If you are editing the info.plist XML, you can add it using this new tags

<key>UIPrerenderedIcon</key>
<string>YES</string>

And then you`’ll see your icon without this effect.

12/08/09

Using Store Kit Framework

Filed under: iPhone Dev SDK by Tags: — Tesh @ 16:59

One of the new framework in firmware 3.0 is the Store Kit. It can be very usefull to get a new business model in iPhone applications. For example, you can create a subscription magazine app where you ask for payment on a monthly, yearly or periodic basis of your choice. Sell extra levels to extend the experience of your game,…

The main steps to use this framework are:

  • - Create “In App Purchase Test User” in iTunes Connect Portal.
  • - Have create App ID in the Developer Portal and enabled in-App purchases for that.
  • - Create the new App on in iTunes Connect Portal, and Register a product for this App.
  • - Develop the store in your App.

More about this post

07/08/09

SoundEngine.cpp building errors in SDK 3.0

Filed under: iPhone Dev SDK by Marc @ 17:52

Hi everyone,

I’m back with another fix that is usefull if you are using the SoundEngine.cpp library combined with the 3.0 version of the iPhone OS.

This morning I needed to use this lib for one of the projects I’m working in, but when I added the library to the project and tried to compile, it came up with several understanding and anoying errors. I don’t know exactly why, but it stopped compiling since the version 3.0 came out.
I’ve tried and I can confirm that it still compiles perfectly with the 2.2 version of the SDK.

The solution I’m posting is simple, I’ve done some searches using Google, of course. I found several solutions to the problem, but only one of them is the easyest and simpliest to implement.

You just have to solve only two of the errors listed by the compiler to solve them all:

1. "crosses initialization of OSStatus err" in line 686:
OSStatus err = AudioFileGetPropertyInfo(inFileInfo->mAFID, kAudioFilePropertyChannelLayout, &size, NULL);

2. "crosses initialization of bool isFormatVBR" in line 722:
bool isFormatVBR = (inFileInfo->mFileFormat.mBytesPerPacket == 0 || inFileInfo->mFileFormat.mFramesPerPacket == 0);

You just have to move the initialization of these structures, just a few lines before.
If you take a look at the source, the line just before both initializations it’s an AssertNoError that redirects to the label end in case of no error. You just have to initialize this structures:

OSStatus err;
bool isFormatVBR;

Just before of that AssertNoError call, at the beginning of the method/function is a good place. It seems like the compiler doesn’t like the order of the labels, maybe it became more strict since the update.

23/07/09

How to change the UITableViewCell backgroundColor / backgroundView

Filed under: iPhone Dev SDK by Marc @ 08:36

I recently found out that the properties backgroundColor and backgroundView of an UITableViewCell can’t be changed easily, or at least using the setBackgroundColor message and setBackgroundView.

If you try the setBackgroundColor nothing happens and if you try the setBackgroundView a white rectangle appears just under the textLabel I think it’s the textLabel backgroundColor, but changing this property to [UIColor ClearColor](that means transparent), doesn’t do anything.

Surfing the forums I found one solution that works for me and I’d like to share. In my case I was re-writting the UItableViewCell definition to build my own “Custom UITableViewCell” ’cause I need to display the information I had in an specific way, if this is your case too, you can override the layoutSubviews method to this one:

- (void)layoutSubviews {     
    [super layoutSubviews];     
    [self setBackgroundColor:[UIColor clearColor]];
}

This changes the background to transparent and allows to show up my backgroundView. If you don’t want to change the backgroundView and you just want to change the backgroundColor you just have to set up the color you like where I set up the “clearColor”

« Newer Posts