最近我发现了来自Github的webrtc-ios示例.当我浏览项目时,我注意到VideoView类使用静态方法,我不确定是否有必要.VideoView是UIView的子类,它覆盖了两个init方法,initWithFrame:和initWithCoder:.我知道覆盖这些init方法然后使用一些方法来设置其他东西是很正常的- (void)setup;.
但是VideoView类使用静态函数static void init(VideoView *self).问题是使用静态函数与普通ObjC方法有什么好处?
VideoView类中的代码如下所示:
-(id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
init(self);
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
init(self);
}
return self;
}
static void init(VideoView *self) { ... }
Run Code Online (Sandbox Code Playgroud) 我用来UICollectionViewDiffableDataSource填充UICollectionView数据。我的理解是,DiffableDataSource通过使用来比较项目==,然后如果项目相等,它会比较hash值以查看是否发生了变化。
但根据我得到的错误,情况并非如此。
Diffable data source detected item identifiers that are equal but have different hash values. Two identifiers which compare as equal must return the same hash value. You must fix this in the Hashable (Swift) or hash property (Objective-C) implementation for the type of these identifiers
Run Code Online (Sandbox Code Playgroud)
就我而言,我有与 uniqueID 进行比较的项目,并且 hashValue 由用户输入的值确定。如果 == 和 hashValue 不能不同,那么使用它们有什么意义呢?
uikit uicollectionview swift uicollectionviewdiffabledatasource
ios ×2
cocoapods ×1
github ×1
objective-c ×1
swift ×1
uicollectionviewdiffabledatasource ×1
uikit ×1
webrtc ×1