检查UIView中初始化的Struct值

问题描述 投票:0回答:1

我有一个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")
    }
}

我不知道我在做什么错。有人可以帮我吗?

ios swift struct uiview initialization
1个回答
1
投票

将具有常量的结构改为常量

enum WishlistMode {
    case isCreating
    case isChanging
}

并且UIView代码从Constants.WishlistMode.Type更改为Constants.WishlistMode

© www.soinside.com 2019 - 2024. All rights reserved.