3

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.

shashwat
  • 7,851
  • 9
  • 57
  • 90
crizzwald
  • 1,037
  • 2
  • 14
  • 30

2 Answers2

1

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?

Community
  • 1
  • 1
terry
  • 1,569
  • 11
  • 19
0

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.

CSJordan
  • 461
  • 5
  • 6