检查 UIView 中的初始化结构值
Check initialized Struct value inside UIView
我有一个 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
我有一个 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