Skip to content

Instantly share code, notes, and snippets.

@ramiresnas
Created November 20, 2017 21:02
Show Gist options
  • Save ramiresnas/6bef9142339f4557da8f5358c99c532f to your computer and use it in GitHub Desktop.
Save ramiresnas/6bef9142339f4557da8f5358c99c532f to your computer and use it in GitHub Desktop.
Navegação entre meses
import Foundation
class NavigationMonth{
var current = Date()
var next : Date{return Calendar.current.date(byAdding: .month, value: 1, to: current)!}
var before : Date{return Calendar.current.date(byAdding: .month, value: -1, to: current)!}
init() {} // deve possuir um inicializador em branco
init(date : Date) {
current = date
}
}
//exemplo de implemantacao
let dateFormater = DateFormatter()
dateFormater.dateFormat = "MMMM"
var month = NavigationMonth()
//altere para que seja sua @IBAction no butao 'avancar'
func next() -> String{
let nextMonthString = dateFormater.string(from: month.next)
month = NavigationMonth(date: month.next)
return nextMonthString
}
//altere para que seja sua @IBAction no butao 'voltar'
func before() -> String{
let beforeMonthString = dateFormater.string(from: month.before)
month = NavigationMonth(date: month.before)
return beforeMonthString
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment