1
"2017 년 1 월 14 일 토요일"과 같이 현재 날짜를 표시하기 위해 클래스의 청사진을 작성하려고하지만 배열을 만들 수 없습니다. Swift 3의 달력 구성 요소에 대해 설명합니다. 아래 해에 수행 한 것처럼 별도의 변수로 나누고 각 변수를 문자열로 결합해야합니까?Calendar.components는 Swift 3의 배열 리터럴과 함께 사용할 수 없습니다.
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 –