Swift 2.0 - `nil`或`0'枚举参数 [英] Swift 2.0 - `nil` or `0` enum arguments

查看:109
本文介绍了Swift 2.0 - `nil`或`0'枚举参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Swift 2.0中遇到了几个功能,并想知道是否有工作。现在似乎没有办法在Swift 2.0中没有指定枚举参数。例如,这两种方法似乎需要不同于 nil 0 之类的东西。有没有办法这个?

I've run into this a on a couple functions in Swift 2.0 and wondering if there is a work around. There seems to be no way to not specify enum arguments in Swift 2.0 now. For example, these two methods seem to require something other than nil or 0 be passed in. Is there a way around this?

// Cannot invoke '...' with argument list of type ... options: Int
NSCalendar.currentCalendar().dateByAddingComponents(components, fromDate: self.date, options: 0)
NSJSONSerialization.JSONObjectWithData(data, options: 0)

// Cannot invoke '...' with argument list of type ... options: nil
NSCalendar.currentCalendar().dateByAddingComponents(components, fromDate: self.date, options: nil)
NSJSONSerialization.JSONObjectWithData(data, options: nil)


推荐答案

选项现在被指定为一个集合,所以只是通过一个空集: options:[]

Options are now specified as a set, so just pass an empty set: options: [].

这篇关于Swift 2.0 - `nil`或`0'枚举参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆