crizzwald
crizzwald

Reputation: 1037

does objective-c has generic types (and with constraints) similar to c#?

Example Generic Repository:

public interface IGenericRepository<T> where T : class
{
    IQueryable<T> GetAll();
    IQueryable<T> FindBy(Expression<Func<T, bool>> predicate);
    void Add(T entity);
    void Delete(T entity);
    void Update(T entity);
    void Save();
}

I am looking to use the repository pattern in model layer of my application and can't seem to find much on the subject when comparing c# generic types to objective-c.

Upvotes: 3

Views: 1785

Answers (2)

CSJordan
CSJordan

Reputation: 461

As of Xcode 7, Objective C and Swift 2 now support Generics.

They are defined like this @interface NSArray<__covariant ObjectType> or @interface NSDictionary<KeyType, ObjectType>

as taken from the header file of NSArray and NSDictionary. They provide type checking at compile time.

Upvotes: 0

terry
terry

Reputation: 1587

No, there're no generic types in objective-c.

Use of generics is closest to the use of id in Objective-C collection classes such as NSDictionary.

you could refer to C# programming introduced to Objective-C programmers

and this similar question on SO Are there strongly-typed collections in Objective-C?

Upvotes: 1

Related Questions