功能特定類型的我想是這樣的: 如何實現迅速
enum ArgType { case Case1, case Case2 }
func foo(arg: ArgType) {
// code
}
上面的代碼工作,但ArgType
僅用於功能foo
,所以我更喜歡以某種方式在「限制」函數的範圍,我應該怎麼做?
func foo(arg: T) where T = enum _ { case Case1, case Case2 } {
// code
}
// this doesn't compile, I put this here just for an example for what I want
我覺得這個問題有點不清楚,你想達到什麼目的? –
@AhmadF,對不起。考慮到問題中的代碼,我可以編寫另一個函數'bar(arg:ArgType)',因爲'ArgType'對bar也是可見的,我想要阻止它。 –