CocoaUser
CocoaUser

Reputation: 1429

Basic questions about OptionSetType

I try to get clear of OptionSetType Protocol and I have some basic questions.
1) Does the options is an Array type or a Set type?
2) Can I access each element of options using for...in loop or for loop
thanks in advance

let options: NSDirectoryEnumerationOptions = [.SkipsHiddenFiles, .SkipsPackageDescendants, .SkipsSubdirectoryDescendants]

Upvotes: 0

Views: 153

Answers (1)

user3441734
user3441734

Reputation: 17544

1) no

2) no

see this 'self explanatory' snippet

import Foundation

let options: NSDirectoryEnumerationOptions = [.SkipsHiddenFiles, .SkipsPackageDescendants, .SkipsSubdirectoryDescendants]

let res = options.rawValue == NSDirectoryEnumerationOptions.SkipsHiddenFiles.rawValue | NSDirectoryEnumerationOptions.SkipsPackageDescendants.rawValue | NSDirectoryEnumerationOptions.SkipsSubdirectoryDescendants.rawValue

print(res) // true
dump(options)
/*
▿ __C.NSDirectoryEnumerationOptions
  - rawValue: 7
*/

you can initialize it other way, with the same result

let options2 = NSDirectoryEnumerationOptions(rawValue: NSDirectoryEnumerationOptions.SkipsHiddenFiles.rawValue | NSDirectoryEnumerationOptions.SkipsPackageDescendants.rawValue | NSDirectoryEnumerationOptions.SkipsSubdirectoryDescendants.rawValue)

options2 == options // true

Upvotes: 1

Related Questions