我有一个UIView
和一个custom-init
,所以我可以更改它的mode
:
var wishlistMode: Constants.WishlistMode.Type?
init(wishlistMode: Constants.WishlistMode.Type) {
self.wishlistMode = wishlistMode
super.init(frame: CGRect.zero)
setupViews()
}
为此,我创建了此struct
:
struct Constants: Equatable {
struct WishlistMode: Equatable {
static let isCreating = WishlistMode.self
static let isChanging = WishlistMode.self
}
/*...*/
}
在我的UIView
内部,我有这个function
检查WishListMode
,但是即使我用isChanging
初始化了view
,它仍然总是打印出let v = CreateNewListView(wishlistMode: Constants.WishlistMode.isCreating)
:
func checkWishlistMode(){
if self.wishlistMode == Constants.WishlistMode.isChanging {
print("isChanging")
} else if self.wishlistMode == Constants.WishlistMode.isCreating {
print("isCreating")
}
}
我不知道我在做什么错。有人可以帮我吗?
将具有常量的结构改为常量
enum WishlistMode {
case isCreating
case isChanging
}
并且UIView代码从Constants.WishlistMode.Type
更改为Constants.WishlistMode