我尝试清除OptionSetType协议,我有一些基本问题。
1)选项是数组类型还是设置类型?
2)我可以使用for ... in循环或for循环访问每个选项元素
提前谢谢
let options: NSDirectoryEnumerationOptions = [.SkipsHiddenFiles, .SkipsPackageDescendants, .SkipsSubdirectoryDescendants]
答案 0 :(得分:1)
1)没有
2)没有
请参阅此“自我解释”代码段
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
*/
你可以用其他方式初始化它,结果相同
let options2 = NSDirectoryEnumerationOptions(rawValue: NSDirectoryEnumerationOptions.SkipsHiddenFiles.rawValue | NSDirectoryEnumerationOptions.SkipsPackageDescendants.rawValue | NSDirectoryEnumerationOptions.SkipsSubdirectoryDescendants.rawValue)
options2 == options // true