swfit初心者です。
課題でカレンダーを作ることになり、Web記事のコードを参考に試してみたのですが、おそらくバージョンの違い所以で、下記の箇所でエラーが出ます。
// インスタンス作成時にエラーが出たので修正
let calendar = NSCalendar.currentCalendar() // Fix => Cannot call value of non-function type 'Calendar'. replace with() // ! => 'currentCalendar' has benn renamed to 'current' let calendar = NSCalendar.current //自動修正結果
このインスタンスからメソッドを呼び出した箇所でエラーになっており、修正方法がわかりません。
// Fix => 'NSCalendarOptions' has benn renamed to 'NSCalendar.Options' return calendar.dateByAddingComponents(dateComponents, toDate: self, options: NSCalendarOptions(rawValue: 0))! // ! => Value of type 'Calendar' has no member 'dateByAddingComponents' return calendar.dateByAddingComponents(dateComponents, toDate: self, options: NSCalendar.Options(rawValue: 0))! }
解決方法ご存知の方、よろしくお願い致します。
環境:Swift3.3
参考記事:https://qiita.com/sakuran/items/3c2c9f22cbcbf4aff731
回答1件
あなたの回答
tips
プレビュー