Tag: Objective C
What is Delegation in iOS ?
Delegation is one of the commonly used pattern in iOS. This is used tell an object to act on behalf of another. Refer to Apple documentation for detailed information on delegate pattern. Let us see this with an example program that uses UITextFieldDelegate. This is a SingleView Project with one UITextField control. #import “ViewController.h” @interface…
Variables in Objective-C
Objective-C also uses variables for storing data in memory like other programming languages. The variables are defined based on the type data type that will be stored. The general rule followed for naming variable are Use the camel case convention for variable i.e the first word in lowercase and second word in uppercase. For example…
NSLog datatype formatting option in Objective-C
NSLog in Objective-C is function call that is useful during debugging of a program. A typical NSLog example is NSLog(@” How to use NSLog”); The above statement prints the message ” How to use NSLog ” in console window. If you want to print the value of Objective-C variable or data type then you need…
Different data types in Objective-C
Objective-C like any other programming languages has different data types like int, float, double, char and id. Data types are used for specifying the kind of data that is being stored in a variable. For example, the below code stores a single character to a variable “flag” char flag = ‘1’ Data type – char…
‘NSInvalidUnarchiveOperationException’, reason: ‘Could not instantiate class named MKMapView’
Problem :- Xcode project with MapView control displays the error “‘NSInvalidUnarchiveOperationException’, reason: ‘Could not instantiate class named MKMapView’” Solution :- The ‘Could not instantiate class named MKMapView’ error is displayed when the Xcode project with MapView control on xib does not include the MapKit library as part of the Link Libraries. Select the Xcode project…
Objective-C – What are Categories?
Categories in Objective-C are used for adding extra functionality to a class without accessing the source code of the class and without subclassing it. Let us see this with an example by adding an additional method to NSNumber that just writes the value of the NSNumber argument to NSLog. Create Project Create a new Command…
Code Example – Check for Prime Number Objective C
This is a simple Objective C program written to check whether a number is a Prime number. // // main.m // PrimeNumbers // // Created by Ravi Shankar on 10/02/12. // Copyright (c) 2012 rshankar.com. All rights reserved. // #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { @autoreleasepool { int number;…
Dissecting Objective-C program
We have already seen couple of examples in Objective-C like writing your first program in Objective-C and adding Objective-C classes. Now let us try and analyze the code to learn basic coding on Objective-C program. Adding Comments The very basic thing to learn is any programming language is “how to add comments”. In Objective-C you…