optionsettype

OptionSetType and enums

和自甴很熟 提交于 2019-12-18 19:08:49
问题 I have an enum named ProgrammingLanguage : enum ProgrammingLanguage { case Swift, Haskell, Scala } Now I have a class named Programmer with the following property: let favouriteLanguages: ProgrammingLanguage = .Swift Seeing how a programmer could have several favourite languages, I'd thought it'd be nice to write something like this: let favouriteLanguages: ProgrammingLanguage = [.Swift, .Haskell] After a bit of research, I realized that I need to conform to OptionSetType , but in doing so, I

How to display OptionSet values in human-readable form?

元气小坏坏 提交于 2019-12-09 09:08:43
问题 Swift has the OptionSet type, which basically adds set operations to C-Style bit flags. Apple is using them pretty extensively in their frameworks. Examples include the options parameter in animate(withDuration:delay:options:animations:completion:) . On the plus side, it lets you use clean code like: options: [.allowAnimatedContent, .curveEaseIn] However, there is a downside as well. If I want to display the specified values of an OptionSet , there doesn't seem to be a clean way to do it: let

How to display OptionSet values in human-readable form?

情到浓时终转凉″ 提交于 2019-12-03 11:42:47
Swift has the OptionSet type, which basically adds set operations to C-Style bit flags. Apple is using them pretty extensively in their frameworks. Examples include the options parameter in animate(withDuration:delay:options:animations:completion:) . On the plus side, it lets you use clean code like: options: [.allowAnimatedContent, .curveEaseIn] However, there is a downside as well. If I want to display the specified values of an OptionSet , there doesn't seem to be a clean way to do it: let options: UIViewAnimationOptions = [.allowAnimatedContent, .curveEaseIn] print("options = " + String

OptionSetType and enums

三世轮回 提交于 2019-11-30 17:30:55
I have an enum named ProgrammingLanguage : enum ProgrammingLanguage { case Swift, Haskell, Scala } Now I have a class named Programmer with the following property: let favouriteLanguages: ProgrammingLanguage = .Swift Seeing how a programmer could have several favourite languages, I'd thought it'd be nice to write something like this: let favouriteLanguages: ProgrammingLanguage = [.Swift, .Haskell] After a bit of research, I realized that I need to conform to OptionSetType , but in doing so, I've raise the following 3 errors: ProgrammingLanguage does not conform to SetAlgebraType OptionSetType

Whats the Swift animate WithDuration syntax?

…衆ロ難τιáo~ 提交于 2019-11-26 13:49:22
问题 I'm porting an older app over to Xcode 7 beta and I'm getting an error on my animations: Cannot invoke 'animateWithDuration' with an argument list of type '(Double, delay: Double, options: nil, animations: () -> _, completion: nil)' Here's the code: UIView.animateWithDuration(0.5, delay: 0.3, options: nil, animations: { self.username.center.x += self.view.bounds.width }, completion: nil) This works in Xcode 6 so I'm assuming this is an update in Swift. So my question is: What's the Swift 3