Extension function for get the date is 1'st of the month iOS swift
Problem:
I'm having one date with me.I want to check that if my date is first day of the month.How can i achieve that?
Solution:
extension Date {
func isFirstDayOfMonth() -> Bool {
let calendar = Calendar.current
let components = (calendar as NSCalendar).components(.day, from: self)
let dayOfMonth = components.day
switch dayOfMonth {
case 1:
return true
default:
return false
}
}
}
The above function will return the boolean as that date is first day then return true otherwise it returns false
Call the above function will be like below.
mydate.isFirstDayOfMonth()
Comments
Post a Comment