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(.dayfromself)

        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

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift