25

I went through the Text Kit Tutorial on raywenderlich.com and the line

edited(.EditedCharacters | .EditedAttributes, range: range, changeInLength: (str as NSString).length - range.length)

produces the following error:

No '|' candidates produce the expected contextual result type 'NSTextStorageEditActions'

The error goes away when I change the first argument to:

edited(.EditedCharacters, range: range, changeInLength: (str as NSString).length - range.length)

I also tried using "OR" and "||" without any success.

Swift 2.2 and iOS 9.2

Morgan
  • 1,280
  • 1
  • 14
  • 15
  • 14
    [`NSTextStorageEditActions`](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextStorage_Class/#//apple_ref/c/econst/NSTextStorageEditedCharacters) is nowadays (seems like the tutorial is pre-Swift 2.0) conforming to `OptionSetType` protocol, and you can include several options using the array-like syntax `[.OptionA, .OptionB]`. E.g., in your example, `edited([.EditedCharacters, .EditedAttributes], ... `. For details, [see e.g. this Q&A](http://stackoverflow.com/questions/24066170/how-to-create-ns-options-style-bitmask-enumerations-in-swift). – dfrib Apr 11 '16 at 22:14
  • Ahh! That worked - thanks! – Morgan Apr 11 '16 at 22:20

2 Answers2

48

@dfri is correct. To illustrate another example of using the pipe, "|", is when doing the autoResizingMask for UIImageView as follows:

imageView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight, ...]

Of course you'd replace the ... with other UIViewAutoresizing options.

Good luck!

kbpontius
  • 3,867
  • 1
  • 30
  • 34
2

Put them all in an array like below:

instead of pipe

let timeDateComponents = calendar.components(NSCalendarUnit.Hour| NSCalendarUnit.Minute| NSCalendarUnit.Second, fromDate: NSDate())

try this

let timeDateComponents = calendar.components([NSCalendarUnit.Hour, NSCalendarUnit.Minute, NSCalendarUnit.Second], fromDate: NSDate())
Arjun Kalidas
  • 919
  • 9
  • 14