Tag Archives: objective-c

String matching and comparison in Objective-C (Cocoa Framework)

This snippet shows how to search for a string within another string and how to check if two strings are equal. NSString* needle = @”hello”; NSString* haystack = @”hello world”; NSRange matching = [haystack rangeOfString : needle]; // Searching for a string within another string if(matching.location == NSNotFound){ // Needle not found in haystack } [...]

Posted in Objective-C | Also tagged , , , , | Leave a comment

UIWebView to display web content (Cocoa Framework)

UIWebViews can be used to display web pages (for example, within iPhone applications). The snippets below demonstrate a view controller to display http://snipd.net .

Posted in Objective-C | Also tagged , , , , , , , , | Leave a comment

Asynchronous HTTP POST requests in Objective-C (Cocoa Framework)

The snippets below contain a header file and an Objective-C class to send HTTP POST requests.

Posted in Objective-C | Also tagged , , , , , , | 1 Comment

Instantiation in Objective-C

Instantiation in Objective-C consists of allocating memory for the instance and calling init. NSString* foo = [[NSString alloc] init];

Posted in Objective-C | Also tagged , , , | Leave a comment

Logging output in Objective-C (Cocoa Framework)

NSLog can be used for outputting messages to the console for debugging purposes. – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // Add the tab bar controller’s view to the window and display. [self.window addSubview:tabBarController.view]; [self.window makeKeyAndVisible]; NSLog(@”Application didFinishLaunchingWithOptions”); return YES; } Output: NSLog also supports format specifiers such [...]

Posted in Objective-C | Also tagged , , , , , | Leave a comment