3

示例通用存储库:

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();
}

我希望在我的应用程序的模型层中使用存储库模式,并且在将 c# 泛型类型与 Objective-c 进行比较时似乎找不到太多关于该主题的信息。

4

2 回答 2

1

不,objective-c 中没有泛型类型。

在 NSDictionary 等 Objective-C 集合类中,泛型的使用最接近 id 的使用。

您可以参考 Objective-C 程序员介绍的 C# 编程

以及关于 SO Are there strong-typed collections in Objective-C 的类似问题?

于 2013-05-20T23:24:01.050 回答
0

从 Xcode 7 开始,Objective C 和 Swift 2 现在支持泛型。

它们是这样定义的, @interface NSArray<__covariant ObjectType>或者 @interface NSDictionary<KeyType, ObjectType>

取自 NSArray 和 NSDictionary 的头文件。它们在编译时提供类型检查。

于 2015-09-23T19:29:21.233 回答