Sunday, March 17, 2013

Cheat Sheet

C# Objective-C
Initialize String
string str = @"x"; NSString *str = @"x";
Append String
string str1 = "a";
string str2 = "b";
string str3 = str1 + str2
NSString *str1 = @"a";
NSString *str2 = @"b";
NSString *str3 = [str1 stringByAppendingString:str2];
More
//Definition
//Not required

//Declaration
void MyFunction()
{
}

//Invocation
MyFunction();
//Definition (ViewController.h)
@interface ViewController : UIViewController
-(void) MyFunction;
@end

//Declaration (ViewController.m)
@implementation ViewController
- (void) MyFunction
{
}
@end

//Invocation (ViewController.m)
[self MyFunction];


//Definition
//Not required

//Declaration
string GetGreetings(string strName)
{
return "Hello " + strName;
}

//Invocation
string strResult = GetGreetings("Usman");

//Definition (ViewController.h)
@interface ViewController : UIViewController

-(NSString *) GetGreetings:(NSString *)strMessage;

@end

//Declaration (ViewController.m)
@implementation ViewController

-(NSString *) GetGreetings:(NSString *)strMessage;
{
    return [@"Hello " stringByAppendingString:strMessage];
}

@end

//Invocation (ViewController.m)

NSString *strResult = [self GetGreetings: @"Usman"];















No comments:

Post a Comment