i want to write a function, which returns specific NSCalendarUnits from a String. My function therefore takes as many NSCalendarUnits as arguments as the user wants to.
public extension String{
func calendarComponents(units: NSCalendarUnit, separateString: String) -> NSDateComponents{
// now i want to know which units the user specified
// so i can scan the string for integerValues and add them to
// the corresponding component
}
}
as a result i want the user to define a String like var myStringDate = "4/5" and then use the function
myStringDate.calendarComponents(units: .CalendarUnitMonth |
.CalendarUnitWeekday, "/")
and then get a NSDateComponent object with .month = 4 and .weekday = 5.
i do know how to scan the string for all the needed Values, but i don't know, how to add those values to the right component attribute.
Aucun commentaire:
Enregistrer un commentaire