问题描述:

Is it possible to call one or another method depending a Bool value? I wish to do this:

var isLocked: Bool

{

didSet

{

// This is not Swift but indicates what I'm looking for.

self.activityIndicator.(isLocked ? startAnimating() : stopAnimating())

}

}

I'm looking to do this using existing Swift 2 (or 3) language features; without class extensions.

Possibly a duplicate, but couldn't find.

网友答案:

How about:

didSet {
    isLocked ? self.activityIndicator.startAnimating() :
        self.activityIndicator.stopAnimating()
}
相关阅读:
Top