下記のような関数をswiftで定義したときに、String型を返す関数だけMissing return in instance method expected to return 'String'
というエラーが出ます。
戻り値の型がVoidかStringの違いだと思うのですがなぜVoidだとエラーが出ずにStringではエラーが出るのでしょうか?
swift
1 enum Test{ 2 case a 3 case b 4 } 5 6 func hoge(test:Test)->Void{ 7 switch test{ 8 case .a: 9 return () 10 case .b: 11 break 12 } 13 } 14 15 func hoge(test:Test)->String{ 16 switch test{ 17 case .a: 18 return "" 19 case .b: 20 break 21 } 22 }
戻り値の型が String なら、String の値を返す必要があります。