'what is the difference between @compatibility_alias and typedef use on @class in Objective-C

Is there any difference between :

@compatibility_alias AliasClassName ExistingClassName

and

typedef ExistingClassName AliasClassName;


Solution 1:[1]

They have different way to use. @compatibility_alias is a reserved word of Objective-C,@compatibility_alias allows existing classes to be aliased by a different name.

For example PSTCollectionView uses @compatibility_alias to significantly improve the experience of using the backwards-compatible, drop-in replacement for UICollectionView:

// Allows code to just use UICollectionView as if it would be available on iOS SDK 5.
// http://developer.apple.    com/legacy/mac/library/#documentation/DeveloperTools/gcc-3.   3/gcc/compatibility_005falias.html
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 60000
@compatibility_alias UICollectionViewController PSTCollectionViewController;
@compatibility_alias UICollectionView PSTCollectionView;
@compatibility_alias UICollectionReusableView PSTCollectionReusableView;
@compatibility_alias UICollectionViewCell PSTCollectionViewCell;
@compatibility_alias UICollectionViewLayout PSTCollectionViewLayout;
@compatibility_alias UICollectionViewFlowLayout PSTCollectionViewFlowLayout;
@compatibility_alias UICollectionViewLayoutAttributes     PSTCollectionViewLayoutAttributes;
@protocol UICollectionViewDataSource <PSTCollectionViewDataSource> @end
@protocol UICollectionViewDelegate <PSTCollectionViewDelegate> @end
#endif

Using this clever combination of macros, a developer can develop with UICollectionView by including PSTCollectionView–without worrying about the deployment target of the final project. As a drop-in replacement, the same code works more-or-less identically on iOS 6 as it does on iOS 4.3.

Then,typedef is a reserved keyword in C like programming language .It is used to create an alias name for another data type,not only for a class,but also for a basic data type,like struct,pointers,even for a function. Here is some examples:

typedef struct Node Node;
struct Node {
    int data;
    Node *nextptr;
};


typedef int *intptr;   // type name: intptr
                       // new type: int*

intptr ptr;            // same as: int *ptr

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1