Archive for August, 2009

Cocoa : Write a Flat File

Sunday, August 9th, 2009

Code:

NSError *error;

//write to file
NSString *FileContent ;
FileContent = [txtname stringValue] ;

[FileContent writeToFile:FileName atomically:YES encoding:NSUnicodeStringEncoding error:&error];

Cocoa : Add Two string into one

Sunday, August 9th, 2009

Code

NsString *str1= @”My Frist String ” ;

NsString *str2= @”My Second String ” ;

str1 = [[str1 stringByAppendingString:str1] retain];

// return str1 My Frist String My Second String

Cocoa : Get Mac Serial Number Using AppleSript

Sunday, August 9th, 2009

  //Cocoa : Get Mac Serial Number Using AppleSript OR Run A AppleScript in Cocoa

NSDictionary* errorDict;
NSAppleEventDescriptor* returnDescriptor = NULL;

NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
@”\
set SerialNumber to word -1 of (do shell script \”ioreg -l | grep IOPlatformSerialNumber\”) \n\
–display dialog (SerialNumber) \n\
return SerialNumber”

];
returnDescriptor = [[scriptObject executeAndReturnError: &errorDict]stringValue];

Cocoa : Change Sreen Size Run Time

Sunday, August 9th, 2009

    int newWinHeight = 624; // New Vertical height
int newWinWidth = 802; // New Horizontal width
NSRect r;

r = NSMakeRect([window1 frame].origin.x - (newWinWidth - (int)(NSWidth([window1 frame]))), [window1 frame].origin.y - (newWinHeight - (int)(NSHeight([window1 frame]))), newWinWidth, newWinHeight);
[window1 setFrame:r display:YES animate:YES];

Cocoa : String Replace

Sunday, August 9th, 2009

Code :

In Cocoa stringByReplacingOccurrencesOfString is Same Like php str_replace

NsString *aString = @” My Name Is Prosenjit Sarkar” ;
NsString *SearchWord = @”Prosenjit Sarkar” ;
NsString *ReplaceValue = @”Your Name”
aString = [aString stringByReplacingOccurrencesOfString:SearchWord withString:ReplaceValue];

// Return  My Name Is Your Name

Cocoa : Hide UnHide a Control

Sunday, August 9th, 2009

  //Make Invisible

[myControl  setHidden:YES] ;
//Make Visible

[myControl  setHidden:NO] ;

Cocoa : Get Current Path Of Application

Sunday, August 9th, 2009

  Code :

NSString *resourcesPath = [[NSBundle mainBundle] resourcePath];

Cocoa : Get String Value of Textbox

Sunday, August 9th, 2009

// txtname is textBox

NsString *myTextValue ;

myTextValue = [txtname stringValue] ;

Cocoa : Check A String Is Null or Not

Sunday, August 9th, 2009

Code: How to Check if a String is blank

NsString  *mystring ;

if ([mystring isEqualToString:@”"]    )
{

// Return True ;

}

Promt a Message Box

Sunday, August 9th, 2009

 Its Very Simple Like

NSRunAlertPanel(@”Your Heading”, @”Your Message”, @”Your Button1″,@”Your Button2″, return);