Static vs. Dynamic Typing in Objective C

we talked about Objective-C being a statically-typed language, meaning that “the type of data each variable (or container) will hold is declared up front?” Well, that’s sort of true, but doesn’t describe the whole picture. I don’t want to overload this post with details about the language, but it’s important to mention that Objective-C is also a dynamic language, which means that some parts of our code can be extended and modified while our apps are running (i.e. after they’ve already been compiled). One example is the use of the generic data type called id. id can be used to represent any kind of data type. It’s the most generic form of specifying data; it simply stands for an “identifier” that is used to reference data. This type of dynamic typing allows for increased flexibility in how we code certain things. In iOS, we often see id used for methods that are tied to controls on the screen, like:

- (IBAction)save:(id)sender;

This is the declaration of a method, which we’ll talk about in an upcoming post. But notice that the sender parameter is of type id. This allows some flexibility in that our app doesn’t care if the sender is a button or an image or whatever else we might want to use to trigger this action.

iOS interview questions with answers

Questions :

 
1.What is latest iOS version?
2.What is latest Xcode version?
3.What is latest mac os version?
4.What is iPad screen size?
5.what is iPhone screen size?
6.What are the features is IOS 6?
7.Who invented Objective c?
8.What is Cococa and cocoa touch?
9.What is Objective c?
10. how declare methods in Objective c? and how to call them?
11. What is property in Objective c?
12.What is meaning of “copy” keyword?
13.What is meaning of “readOnly” keyword?
14.What is meaning of “retain” keyword?
15.What is meaning of “assign” keyword?
16.What is meaning of “automic” keyword?
17.What is meaning of “nonautomic” keyword?
18.What is difference between “assign” and “retain” keyword?
19.What is meaning of “synthesize” keyword ?
20.What is “Protocol” on objective c?
21.What is use of UIApplication class?
22.What compilers apple using ?
23.What is synchronized() block in objective c? what is the use of that?
24. What is the “interface” and “implementation”?
25.What is “private”, “Protected” and “Public” ?
26. What is the use of “dynamic” keyword?
27.What is “Delegate” ?
28.What is “notification”?
29.What is difference between “protocol” and “delegate”?
30.What is “Push Notification”?
31.How to deal with SQLite database?
32.What is storyboard? 
33.What is Category in Objective c?
34.What is block in objective c?
35. How to parse xml? explain in deep.
36.How to parse JSON? explain in deep.
37.How to use reusable cell in UITableview?
38.What is the meaning of “strong”keyword?
39.What is the meaning of “weak” keyword? 
40.What is difference strong and  weak reference ? explain.
41.What is ARC ? How it works? explain in deep.
42. What manual memory management ?  how it work?
43. How to find the memory leaks in MRC?
44.what is use of NSOperation? how NSOperationque works?
45.How to send crash report from device?
46.What is autorealease pool?
47.What happens when we invoke a method on a nil pointer?
48.Difference between nil and Nil.
49.What is fast enumeration?
50. How to start a thread? explain in deep.
51.How to download something from the internet?
52.what is synchronous web request and asynchronous ?
53. Difference between sax parser and dom parser ?
54.Explain stack and heap?
55.What are the ViewController  lifecycle in ios?
56.Difference between coredata & sqlite?
57.Steps for using coredata?
58.Procedure to push the app in AppStore?
59.What are the Application lifecycle in ios?
60.Difference between release and autorelease ?
61.How to start a selector on a background thread
62.What happens if the methods doesn’t exist

Answers:

 
1.What is latest iOS version?
IOS – 7.0
2.What is latest Xcode version?
Xcode-5.0 
3.What is latest mac os version?
 Mac- Mountain Lion (updated on 5/15/13 3:15 AM

Pacific Daylight Time)
 
4.What is iPad screen size?
1024X768
 
5.what is iPhone 5 screen size?
320X480
 
6.What are the features is IOS 6?
 
1.Map :beautifully designed from the ground up (and the sky down)
2.Integration of Facebook with iOS
3.shared photo streams.
4.Passbook – boarding passes, loyalty cards, retail coupons, cinema tickets and more all in one place
5.Facetime – on mobile network as wifi 
6.changed Phone app – *remind me later,*reply with message.
7.Mail – redesigned more streamline interface.
8.Camera with panorama . 
 
7.Who invented Objective c?
Broad cox and Tom Love
 
8.What is Cococa and cocoa touch?
Cocoa is for Mac App development  and cocoa touch is for apples touch devices – that provide all development environment 
 
9.What is Objective c?
*Objective-C is a reflective, object-oriented programming language which adds Smalltalk-style messaging to the C programming language. strictly superset of c.
 
10. how declare methods in Objective c? and how to call them?
 – (return_type)methodName:(data_type)parameter_name : (data_type)parameter_name
 
11. What is property in Objective c?
Property allow declared variables with specification like atomic/nonatmic, or retain/assign 
 
12.What is meaning of “copy” keyword?
copy object during assignment and increases retain count by 1
13.What is meaning of “readOnly” keyword?
 Declare read only object / declare only getter method
 
14.What is meaning of “retain” keyword?
Specifies that retain should be invoked on the object upon assignment. takes ownership of an object
15.What is meaning of “assign” keyword?
Specifies that the setter uses simple assignment. Uses on attribute of scalar type like float,int.
16.What is meaning of “atomic” keyword?
“atomic”, the synthesized setter/getter will ensure that a whole value is always returned from the getter or set by the setter, only single thread can access variable to get or set value at a time
17.What is meaning of “nonatomic” keyword?
In non atomic no such guaranty that value is returned from variable is same that setter sets. at same time
 
18.What is difference between “assign” and “retain” keyword?
 
Retain -Specifies that retain should be invoked on the object upon assignment. takes ownership of an object
Assign – Specifies that the setter uses simple assignment. Uses on attribute of scalar type like float,int.
 
19.What is meaning of “synthesize” keyword ?
ask the compiler to generate the setter and getter  methods according to the specification in the declaration
20.What is “Protocol” on objective c?
A protocol declares methods that can be implemented by any class. Protocols are not classes themselves. They simply define an interface that other objects are responsible for implementing. Protocols have many advantages. The idea is to provide a way for classes to share the same method and property declarations without inheriting them from a common ancestor
21.What is use of UIApplication class?
The UIApplication class implements the required behavior of an application. 
22.What compilers apple using ?
The Apple compilers are based on the compilers of the GNU Compiler Collection.
23.What is synchronized() block in objective c? what is the use of that?
The @synchronized()directive locks a section of code for use by a single thread. Other threads are blocked until the thread exits the protected code.
24. What is the “interface” and “implementation”?
interface declares the behavior of class and implementation defines the behavior of class. 
 
25.What is “private”, “Protected” and “Public” ?
private – limits the scope class variable to the class that declares it.
protected – Limits instance variable scope to declaring and inheriting classes.
public – Removes restrictions on the scope of instance variables
 
26. What is the use of “dynamic” keyword?
Instructs the compiler not to generate a warning if it cannot find implementations of accessor methods associated with the properties whose names follow.
27.What is “Delegate” ?
A delegate is an object that will respond to pre-chosen selectors (function calls) at some point in the future., need to implement the protocol method by the delegate object.
28.What is “notification”?
provides a mechanism for broadcasting information within a program, using notification we can send message to other object by adding observer .
 
29.What is difference between “protocol” and “delegate”?
protocol is used the declare a set of methods that a class that “adopts” (declares that it will use this protocol) will implement. 
Delegates are a use of the language feature of protocols. The delegation design pattern is a way of designing your code to use protocols where necessary.
 
30.What is “Push Notification”?
to get the any update /alert from server .
 
31.How to deal with SQLite database?
Dealing with sqlite database in iOS:
1. Create database : sqlite3 AnimalDatabase.sql
2.Create table and insert data in to  table :
CREATE TABLE animals ( id INTEGER PRIMARY KEY, name VARCHAR(50), description TEXT, image VARCHAR(255) );
 
INSERT INTO animals (name, description, image) VALUES (‘Elephant’, ‘The elephant is a very large animal that lives in Africa and Asia’, ‘http://dblog.com.au/wp-content/elephant.jpg’);
 
3. Create new app –> Add SQLite framework and database file to project
4. Read the database and close it once work done with database :
// Setup the database object
sqlite3 *database;
 
// Init the animals Array
animals = [[NSMutableArray alloc] init];
 
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = “select * from animals”;
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSString *aImageUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
 
// Create a new animal object with the data from the database
Animal *animal = [[Animal alloc] initWithName:aName description:aDescription url:aImageUrl];
 
// Add the animal object to the animals Array
[animals addObject:animal];
 
[animal release];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
 
}
sqlite3_close(database);
 
 
32.What is storyboard? 
With Storyboards, all screens are stored in a single file. This gives you a conceptual overview of the visual representation for the app and shows you how the screens are connected. Xcode provides a built-in editor to layout the Storyboards.
  1. .storyboard is essentially one single file for all your screens in the app and it shows the flow of the screens. You can add segues/transitions between screens, this way. So, this minimizes the boilerplate  code required to manage multiple screens.
  2.   2.   Minimizes the overall no. of files in an app.
 
33.What is Category in Objective c?
A category allows you to add methods to an existing class—even to one for which you do not have the source.
34.What is block in objective c?
Blocks are a language-level feature added to C, Objective-C and C++, which allow you to create distinct segments of code that can be passed around to methods or functions as if they were values. Blocks are Objective-C objects, which means they can be added to collections like NSArray or NSDictionary. They also have the ability to capture values from the enclosing scope, making them similar to closures or lambdas in other programming languages.
35. How to parse xml? explain in deep.
 
Using NSXMLParser.  
Create xml parser object with xml data, set its delegate , and call the parse method with parserObject.
Delegate methods getting called :
 
36.How to parse JSON? explain in deep.
By using NSJSONSerialization. 
For example : NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: &e];
 
37.How to use reusable cell in UITableview?
By using dequeReusableCellWithIdentifier
 
38.What is the meaning of “strong”keyword?
*strong -o “own” the object you are referencing with this property/variable. The compiler will take care that any object that you assign to this property will not be destroyed as long as you (or any other object) points  to it with a strong reference.
39.What is the meaning of “weak” keyword? 
*Weak – weak reference you signify that you don’t want to have control over the object’s lifetime. The object you are referencing weakly only lives on because at least one other object holds a strong reference to it. Once that is no longer the case, the object gets destroyed and your weak property will automatically get set to nil.
40.What is difference strong and  weak reference ? explain.
complier with be responsible for lifetime of object which is declared as strong. for weak object – compiler will destroy object once strong reference that hold weak object get destroyed.
 
41.What is ARC ? How it works? explain in deep.
Automatic reference counting (ARC)  If the compiler can recognize where you should be retaining and releasing objects, and put the retain and release statement in code.
 
42. What manual memory management ?  how it work?
In Manual memory management  developers is responsible for life cycle of object. developer has to retain /alloc and release the object wherever needed.
 
43. How to find the memory leaks in MRC?
By using – 
1.  Static analyzer.
2. Interface builder.
44.what is use of NSOperation? how NSOperationque works?
An operation object is a single-shot object—that is, it executes its task once and cannot be used to execute it again. You typically execute operations by adding them to an operation queueAn NSOperationQueue object is a queue that handles objects of the NSOperation class type. An NSOperation object, simply phrased, represents a single task, including both the data and the code related to the task. The NSOperationQueue handles and manages the execution of all the NSOperation objects (the tasks) that have been added to it.
45.How to send crash report from device?
 
46.What is autorealease pool?
Every time -autorelease is sent to an object, it is added to the inner-most autorelease pool. When the pool is drained, it simply sends -release to all the objects in the pool.
Autorelease pools are simply a convenience that allows you to defer sending -release until “later”. That “later” can happen in several places, but the most common in Cocoa GUI apps is at the end of the current run loop cycle.
47.What happens when we invoke a method on a nil pointer?
 
48.Difference between nil and Nil.
Nil is meant for class pointers, and nil is meant for object pointers
49.What is fast enumeration?
for(id object in objets){
}
 
50. How to start a thread? 
– (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg on NSObject
  NSThread* evtThread = [ [NSThread alloc] initWithTarget:self
                            selector:@selector( saySomething )
                          object:nil ];
    [ evtThread start ];
 
51.How to download something from the internet?
By Using NSURLConnection , by starting connection or sending synchronous request.
 
52.what is synchronous web request and asynchronous ?
In  synchronous request main thread gets block and control will not get back to user till that request gets execute.
In Asynchronous control gets back to user even if request is getting execute.
 
53. Difference between sax parser and dom parser ?
SAX (Simple API for XML)
  1. Parses node by node
  2. Doesn’t store the XML in memory
  3. We can not insert or delete a node
  4. Top to bottom traversing
 
DOM (Document Object Model)
  1. Stores the entire XML document into memory before processing
  2. Occupies more memory
  3. We can insert or delete nodes
  4. Traverse in any direction
 
54.Explain stack and heap?
 
 
55.What are the ViewController  lifecycle in ios?
loadView – viewDidLoad-viewWillAppear-viewDidAppear – viewDisappear  – viewDidUnload
 
56.Difference between coredata & sqlite?
 
There is a huge difference between these two. SQLLite is a database itself like we have MS SQL Server. But CoreData is an ORM (Object Relational Model) which creates a layer between the database and the UI. It speeds-up the process of interaction as we dont have to write queries, just work with the ORM and let ORM handles the backend. For save or retrieval of large data, I recommend to use Core Data because of its abilities to handle the less processing speed of IPhone.
 
 
57.Steps for using coredata?
NSFetchedResultsController – It is designed primarily to function as a data source for aUITableView
 
58.Procedure to push the app in AppStore?
 
59.What are the Application lifecycle in ios?
ApplicationDidFinishLaunchingWithOption -ApplicationWillResignActive- ApplicationDidBecomeActive-ApplicationWillTerminate
 
 
60.Difference between release and autorelease ?
release – destroy the object from memory,
autorelease – destroy the object from memory in future when it is not in use.
 
61.How to start a selector on a background thread
– (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg on NSObject
 
62.What happens if the methods doesn’t exist
App will crash with exception unrecognized selector sent to instance.
 
63. How Push notification works?
Server – Apple server – device by using APNs
 
Delegate methods : 
UITableView:
DataSource –
Configuring a Table View
Inserting or Deleting Table Rows
Reordering Table Rows
 
  Delegate –
Configuring Rows for the Table View
Managing Accessory Views
Managing Selections
Modifying the Header and Footer of Sections
Editing Table Rows
Reordering Table Rows
Copying and Pasting Row Content
 
 UIPickerView-
 DataSource –
Providing Counts for the Picker View
  Delegate –
Setting the Dimensions of the Picker View
Setting the Content of Component Rows
The methods in this group are marked @optional. However, to use a picker view, you must implement either thepickerView:titleForRow:forComponent: or thepickerView:viewForRow:forComponent:reusingView: method to provide the content of component rows.
Responding to Row Selection
 
UITextFeild-
Delegate –
Managing Editing
Editing the Text Field’s Text
 
 UItextView-
 Delegate – Responding to Editing Notifications
Responding to Text Changes
Responding to Selection Changes
 
 MKMapView-
Delegate –
Responding to Map Position Changes
Loading the Map Data
Tracking the User Location
Managing Annotation Views
Dragging an Annotation View
Selecting Annotation Views
Managing Overlay Views
 
NSURLConnection-
Delegate –
Connection Authentication
 
Connection Completion
 
NSURLConnectionDownloadDelegate
 
 NSURLConnection
Preflighting a Request
Loading Data Synchronously
Loading Data Asynchronously
Stopping a Connection
Scheduling Delegate Messages
 
 NSXMLParser-
Handling XML
Handling the DTD
 
 
7.NSURLConnection
Connection Authentication
  • – connection:willSendRequestForAuthenticationChallenge:
  • – connection:canAuthenticateAgainstProtectionSpace:
  • – connection:didCancelAuthenticationChallenge:
  • – connection:didReceiveAuthenticationChallenge:
  • – connectionShouldUseCredentialStorage:
Connection Completion
  • – connection:didFailWithError:
MethodGroup

What are the Dangers of Method Swizzling in Objective C?

Using method sizzling is like using sharp knives in the kitchen. Some people are scared of sharp knives because they think they’ll cut themselves badly, but the truth is that sharp knives are safer.

Method swizzling can be used to write better, more efficient, more maintainable code. It can also be abused and lead to horrible bugs.

Background

As with all design patters, if we are fully aware of the consequences of the pattern, we are able to make more informed decisions about whether or not to use it. Singletons are a good example of something that’s pretty controversial, and for good reason — they’re really hard to implement properly. Many people still choose to use singletons, though. The same can be said about swizzling. You should form your own opinion once you fully understand both the good and the bad.

Discussion

Here are some of the pitfalls of method swizzling:

  • Method swizzling is not atomic
  • Changes behavior of un-owned code
  • Possible naming conflicts
  • Swizzling changes the method’s arguments
  • The order of swizzles matters
  • Difficult to understand (looks recursive)
  • Difficult to debug

These points are all valid, and in addressing them we can improve both our understanding of method swizzling as well as the methodology used to achieve the result. I’ll take each one at a time.

Method swizzling is not atomic

I have yet to see an implementation of method swizzling that is safe to use concurrently1. This is actually not a problem in 95% of cases that you’d want to use method swizzling. Usually, you simply want to replace the implementation of a method, and you want that implementation to be used for the entire lifetime of your program. This means that you should do your method swizzling in +(void)load. The load class method is executed serially at the start of your application. You won’t have any issues with concurrency if you do your swizzling here. If you were to swizzle in +(void)initialize, however, you could end up with a race condition in your swizzling implementation and the runtime could end up in a weird state.

Changes behavior of un-owned code

This is an issue with swizzling, but it’s kind of the whole point. The goal is to be able to change that code. The reason that people point this out as being a big deal is because you’re not just changing things for the one instance of NSButton that you want to change things for, but instead for all NSButton instances in your application. For this reason, you should be cautious when you swizzle, but you don’t nee to avoid it altogether.

Think of it this way… if you override a method in a class and you don’t call the super class method, you may cause problems to arise. In most cases, the super class is expecting that method to be called (unless documented otherwise). If you apply this same thought to swizzling, you’ve covered most issues. Always call the original implementation. If you don’t, you’re probably changing too much to be safe.

Possible naming conflicts

Naming conflicts are an issue all throughout Cocoa. We frequently prefix class names and method names in categories. Unfortunately, naming conflicts are a plague in our language. In the case of swizzling, though, they don’t have to be. We just need to change the way that we think about method swizzling slightly. Most swizzling is done like this:

@interface NSView : NSObject
- (void)setFrame:(NSRect)frame;
@end

@implementation NSView (MyViewAdditions)

- (void)my_setFrame:(NSRect)frame {
    // do custom work
    [self my_setFrame:frame];
}

+ (void)load {
    [self swizzle:@selector(setFrame:) with:@selector(my_setFrame:)];
}

@end

This works just fine, but what would happen if my_setFrame: was defined somewhere else? This problem isn’t unique to swizzling, but we can work around it anyway. The workaround has an added benefit of addressing other pitfalls as well. Here’s what we do instead:

@implementation NSView (MyViewAdditions)

static void MySetFrame(id self, SEL _cmd, NSRect frame);
static void (*SetFrameIMP)(id self, SEL _cmd, NSRect frame);

static void MySetFrame(id self, SEL _cmd, NSRect frame) {
    // do custom work
    SetFrameIMP(self, _cmd, frame);
}

+ (void)load {
    [self swizzle:@selector(setFrame:) with:(IMP)MySetFrame store:(IMP *)&SetFrameIMP];
}

@end

While this looks a little less like Objective-C (since it’s using function pointers), it avoids any naming conflicts. In principle, it’s doing the exact same thing as standard swizzling. This may be a bit of a change for people who have been using swizzling as it has been defined for a while, but in the end, I think that it’s better. The swizzling method is defined thusly:

typedef IMP *IMPPointer;

BOOL class_swizzleMethodAndStore(Class class, SEL original, IMP replacement, IMPPointer store) {
    IMP imp = NULL;
    Method method = class_getInstanceMethod(class, original);
    if (method) {
        const char *type = method_getTypeEncoding(method);
        imp = class_replaceMethod(class, original, replacement, type);
        if (!imp) {
            imp = method_getImplementation(method);
        }
    }
    if (imp && store) { *store = imp; }
    return (imp != NULL);
}

@implementation NSObject (FRRuntimeAdditions)
+ (BOOL)swizzle:(SEL)original with:(IMP)replacement store:(IMPPointer)store {
    return class_swizzleMethodAndStore(self, original, replacement, store);
}
@end

Swizzling changes the method’s arguments

This is the big one in my mind. This is the reason that standard method swizzling should not be done. You are changing the arguments passed to the original method’s implementation. This is where it happens:

[self my_setFrame:frame];

What line does is:

objc_msgSend(self, @selector(my_setFrame:), frame);

Which will use the runtime to look up the implementation of my_setFrame:. Once the implementation is found, it invokes the implementation with the same arguments that were given. The implementation it finds is the original implementation of setFrame:, so it goes ahead and calls that, but the _cmd argument isn’t setFrame: like it should be. It’s now my_setFrame:. The original implementation is being called with an argument it never expected it would receive. This is no good.

There’s a simple solution — use the alternative swizzling technique defined above. The arguments will remain unchanged!

The order of swizzles matters

The order in which methods get swizzled matters. Assuming setFrame: is only defined on NSView, imagine this order of things:

[NSButton swizzle:@selector(setFrame:) with:@selector(my_buttonSetFrame:)];
[NSControl swizzle:@selector(setFrame:) with:@selector(my_controlSetFrame:)];
[NSView swizzle:@selector(setFrame:) with:@selector(my_viewSetFrame:)];

What happens when the method on NSButton is swizzled? Well most swizzling will ensure that it’s not replacing the implementation of setFrame: for all views, so it will pull up the instance method. This will use the existing implementation to re-define setFrame: in the NSButton class so that exchanging implementations doesn’t affect all views. The existing implementation is the one defined on NSView. The same thing will happen when swizzling on NSControl (again using the NSView implementation).

When you call setFrame: on a button, it will therefore call your swizzled method, and then jump straight to the setFrame: method originally defined on NSView. The NSControl and NSView swizzled implementations will not be called.

But what if the order were:

[NSView swizzle:@selector(setFrame:) with:@selector(my_viewSetFrame:)];
[NSControl swizzle:@selector(setFrame:) with:@selector(my_controlSetFrame:)];
[NSButton swizzle:@selector(setFrame:) with:@selector(my_buttonSetFrame:)];

Since the view swizzling takes place first, the control swizzling will be able to pull up the right method. Likewise, since the control swizzling was before the button swizzling, the button will pull up the control’s swizzled implementation of setFrame:. This is a bit confusing, but this is the correct order. How can we ensure this order of things?

Again, just use load to swizzle things. If you swizzle in load and you only make changes to the class being loaded, you’ll be safe. The load method guarantees that the super class load method will be called before any subclasses. We’ll get the exact right order!

Difficult to understand (looks recursive)

Looking at a traditionally defined swizzled method, I think it’s really hard to tell what’s going on. But looking at the alternative way we’ve done swizzling above, it’s pretty easy to understand. This one’s already been solved!

Difficult to debug

One of the confusions during debugging is seeing a strange backtrace where the swizzled names are mixed up and everything gets jumbled in your head. Again, the alternative implementation addresses this. You’ll see clearly named functions in backtraces. Still, swizzling can be difficult to debug because it’s hard to remember what impact the swizzling is having. Document your code well (even if you think you’re the only one who will ever see it). Follow good practices, and you’ll be alright. It’s not harder to debug than multi-threaded code.

Conclusion

Method swizzling is safe if used properly. A simple safety measure you can take is to only swizzle in load. Like many things in programming, it can be dangerous, but understanding the consequences will allow you use it properly.

How to achieve multiple inheritance in Xcode?

Objective-C doesn’t support multiple inheritance, and you don’t need it. Use composition:

@interface ClassA : NSObject {
}

-(void)methodA;

@end

@interface ClassB : NSObject {
}

-(void)methodB;

@end

@interface MyClass : NSObject {
  ClassA *a;
  ClassB *b;
}

-(id)initWithA:(ClassA *)anA b:(ClassB *)aB;

-(void)methodA;
-(void)methodB;

@end