Archive for the ‘Objective C’ Category

13
Jul

In SQLite, the escaping character that is used is single quotes(‘). So if you want to escape ” ‘ “, then you have to use like this ” ” “.

In xcode, this is what you need to do.

If you want to insert the string, xcode’s into the database with the single quotes, then this is what you have to do.

NSString *theStr = [NSString stringWithString:@"xcode's"];

NSString *escapedStr = [thestr stringByReplacingOccurrencesOfString:@"'" withString:@"''"];

Now add the escapedStr into the database instead of theStr.

, , , ,

30
Jun

aString=[aString lowercaseString];

This converts the string to its lowercase.

,

30
Jun

CCSequence *seq = nil;
for (int i=0; i<count; i++) {
// create yourAction
if (!seq)
{
seq = (CCSequence*)yourAction;

}
else
{
seq = [CCSequence actionOne:seq yourAction];
}
}

if (seq)
{
[yourSprite runAction:seq];

}

,

28
Jun

For Initializing the EAGLView the followings are required

Color Buffer

The default color buffer is RGB565. It is a 16-bit buffer, without alpha. In order to use an RGBA8 color buffer, you need to create initialize the EAGLView with:

EAGLView *glView = [EAGLView viewWithFrame:[window bounds] pixelFormat:kEAGLColorFormatRGBA8];

    kEAGLColorFormatRGBA8: Creates an RGBA8 color buffer (32-bit)
    kEAGLColorFormatRGB565: Creates an RGB565 color buffer (16-bit). Faster, but without alpha (default)

Depth Buffer

By default, cocos2d doesn’t use a depth buffer, but you can create one when you initialize the EAGLView with a 16-bit or 24-bit depth buffer. eg:

EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGBA8
depthFormat:GL_DEPTH_COMPONENT24_OES];

    GL_DEPTH_COMPONENT24_OES: 24-bit depth buffer
    GL_DEPTH_COMPONENT16_OES: 16-bit depth buffer
    0: No depth buffer will be created

High Res

Since v0.99.4, the Director can set the color render buffer in High Res mode:

eg:

// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if ([UIScreen instancesRespondToSelector:@selector(scale)])
[director setContentScaleFactor:[[UIScreen mainScreen] scale]];

Since v0.99.5, the suggested way to enable Retina display is:

// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
CCLOG(@”Retina Display Not supported”);

How does it work:

If you have an iPhone4, the screen resolution will be 960×640

MultiSampling, or Full Screen Anti-Aliasing

Multi sampling works on all devices, but on MBX devices the performance impact is severe.

How to enable it:

Don’t use the CC_DIRECTOR_INIT() macro, but use the code from the sample below.

, , , , , , , , , , , , , ,

28
Jun

We can read a word or sentence from a textfield if know the starting location and length by

NSString *edtTxt1 = [txtField.text substringWithRange:NSMakeRange(733, 4)];

27
Jun

For displaying the path at interface of what user selected.

[filePathDisplay setStringValue:filePathString];

‘filePathString’ contains the path of the selected item.

 

, , ,

27
Jun

For getting the file or folder path of what user selected from an NSOpenPanel,

NSString *filePathString = [openPanel filename];

‘filePathString’ will contain the file path of what user selected.

 

, ,

27
Jun

For enabling your open panel to chose the directory.

[urOpenPanel setCanChooseDirectories:YES];

Here ‘urOpenPanel’ is your NSOpenPanel instance.

 

, ,

27
Jun

For changing the title of Open Panel,

[urOpenPanel setTitle:@”Select Any File or Folder”];

Here ‘urOpenPanel’ is your NSOpenPanel instance.

This will set your open panel title to ‘Select Any File or Folder’.

 

,

24
Jun

As we use double quotes as the delimiter for NSString, this is how we can use it inside the string.

NSString *quoteString = [NSString stringWithFormat:@"Boy said:\"I'm a student.\""];

Here inorder to add double quotes(“) inside a string, we have to use \” instead of ” .

, , , , , , ,