1
"2017年1月14日土曜日"のように現在の日付を表示するためにクラスの青写真を作成しようとしていますが、配列を作成できませんSwift 3のカレンダーコンポーネントを使用しています。下の1年間で行ったように別々の変数に分割し、各変数を文字列に結合する必要がありますか?ここでSwift 3の配列リテラルではCalendar.componentsを使用できません
コンパイルされませんよう、私がこれまで持っているものですが、相手のコードを読んでから、それは、過去に働いています
import Foundation
class CurrentCalendarDate {
var currentDateString: String {
get{
let date = Date()
let calendar = Calendar.current
//let components = calendar.component(.year, from: date)
let componetsThatWeWant = calendar.component([.year, .day, .month], from: date)
let readableDate: String = "Today's date is: \(componetsThatWeWant.day) \(componetsThatWeWant.month), \(componetsThatWeWant.year)"
return readableDate
}
}
}
'var currentDateString:Int {'はIntを返します???意味がない –
あなたはDateFormatterを使用することになっています。 'formatter.dateStyle = .full' –
これを参考にして、shortの代わりにfullにすることができます。 http://stackoverflow.com/a/28347285/2303865 –