Wednesday, June 29, 2011

Convert Char to NsString and vice versa

char to NsString

char *a = "Testing";
NSString *aa = [NSString stringWithCString: (const char *)a encoding: NSASCIIStringEncoding];NSLog(@"%@", aa);




#############################################

NSString to c char


char * c_string = [someNSString UTF8String];

Wednesday, June 22, 2011

@selectors in obj-c

elector in Objective C
In short, Selector can either be a name of method or a message to an object when used in the source code. And SEL is the complied form of a Selector.










- (void) fooNoInputs {
NSLog(@"Does selector test");
}

- (void) fooOneInput:(NSString*) first {

// NSLog(@"Does selector test");
NSLog(@"my slectore Logs %@", first);
}

- (void)viewDidLoad
{


//
//##############################################################################

// SELCETOR test

//##############################################################################




[self performSelector:@selector(fooNoInputs)];

[self performSelector:@selector(fooOneInput:) withObject:@"firstc"];













############## difference between

[self playButtonSound]; &

[self performSelector:@selector(playButtonSound)];







Both to the same thing, but [self playButtonSound]; is definitely the normal way to invoke a method in Objective-C. However, using performSelector: allows you to call a method that is only determined at runtime.

@property in objc

Property attributes are special keywords to tell compiler how to generate the getters and setters. Here you specify two property attributes: nonatomic, which tells the compiler not to worry about multithreading, and retain, which tells the compiler to retain the passed-in variable before setting the instance variable.

In other situations, you might want to use the “assign” property attribute instead of retain, which tells the compiler NOT to retain the passed-in variable. Or perhaps the “copy” property attribute, which makes a copy of the passed-in variable before setting.

Sunday, June 19, 2011

Categories in obj-c

// Base Class
@interface ClassA : NSObject
- (NSString *) myMethod;
@end
@implementation ClassA
- (NSString*) myMethod { return @"A"; }
@end

//Category
@interface ClassA (CategoryB)
- (NSString *) myMethod;
@end
@implementation ClassA (CategoryB)
- (NSString*) myMethod { return @"B"; }
@end



Calling the method "myMethod" after including the category nets the result "B".

Friday, June 3, 2011

Php + XML package

//ob_start();

if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") )
{ header("Content-type: application/xhtml+xml;charset=utf-8"); }
else { header("Content-type: text/xml;charset=utf-8"); }
echo "\n";




// Write Code here



ob_get_contents();
//?>

FEEDJIT Live