Created
March 23, 2018 07:11
-
-
Save joshdance/4d10ec39464bd5fd7a476899b4265f8e to your computer and use it in GitHub Desktop.
See if a date is this week in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func calcPushupsThisWeek(){ | |
let calendar = Calendar.current | |
var thisWeeksPushups = 0 | |
let today = Date() | |
let todayComponents = calendar.dateComponents([.weekOfYear], from: today) | |
//I have an array of workout objects with dateOfWorkout properties. You can use any date here | |
for workout in myArray { | |
let workoutComponents = calendar.dateComponents([.weekOfYear], from: workout.dateOfWorkout) | |
if todayComponents.weekOfYear == workoutComponents.weekOfYear | |
{ | |
thisWeeksPushups = thisWeeksPushups + workout.numberOfPushups | |
} | |
} //end for workout | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment