I am kinda new to Swift, but really interested.
I would like to get all the events I stored in a Calendar called "Work" and show them in a tableView.
I was looking for questions like this, but the code shown there seems to be kinda old and not really working. How do I do that? The tableView should be able to show the Title, start and end-Date. Is it possible to get like all Titles in an Array of Strings. Same with the start and end?
Would be awesome to get some tips!
Update:
I declared the variables outside the class.
Now I tried a code that looks like this, thanks to an answer I got here, but I don't get the cells to display anything?! And Yes I already created a testEvent in my Work calendar on the simulator.
override func viewDidAppear(animated: Bool) {
let eventStore = EKEventStore()
switch EKEventStore.authorizationStatusForEntityType(.Event) {
case .Authorized:
readEvents()
case .Denied:
print("Access denied")
case .NotDetermined:
eventStore.requestAccessToEntityType(.Event, completion: { (granted: Bool, NSError) -> Void in
if granted {
self.readEvents()
}else{
print("Access denied")
}
})
default:
print("Case Default")
}
self.tableView.reloadData()
}
func readEvents() {
let eventStore = EKEventStore()
let calendars = eventStore.calendarsForEntityType(.Event)
for calendar in calendars {
if calendar.source.title == "Work" {
let oneMonthAgo = NSDate(timeIntervalSinceNow: -30*24*3600)
let oneMonthAfter = NSDate(timeIntervalSinceNow: +30*24*3600)
let predicate = eventStore.predicateForEventsWithStartDate(oneMonthAgo, endDate: oneMonthAfter, calendars: [calendar])
var events = eventStore.eventsMatchingPredicate(predicate)
for event in events {
titles.append(event.title)
startDates.append(event.startDate)
endDates.append(event.endDate)
}
}
}
}
// MARK: - Table view data source
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return titles.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel!.text = titles[indexPath.row]
cell.detailTextLabel!.text = "From: \(startDates[indexPath.row]) Until: \(endDates[indexPath.row])"
// Configure the cell...
return cell
}
You can try something like this
import EventKit
var titles : [String] = []
var startDates : [Date] = []
var endDates : [Date] = []
var store = EKEventStore()
let calendars = store.calendars(for: .event)
for calendar in calendars {
if calendar.title == "Work" {
let oneMonthAgo = Date(timeIntervalSinceNow: -30*24*3600)
let oneMonthAfter = Date(timeIntervalSinceNow: 30*24*3600)
let predicate = store.predicateForEvents(withStart: oneMonthAgo, end: oneMonthAfter, calendars: [calendar])
let events = store.events(matching: predicate)
for event in events {
titles.append(event.title)
startDates.append(event.startDate)
endDates.append(event.endDate)
}
}
}
(Updated with Swift 5 APIs)
func fetchEventsFromCalendar() -> Void {
let status = EKEventStore.authorizationStatus(for: EKEntityType.event)
switch (status) {
case .notDetermined:
requestAccessToCalendar()
case .authorized:
self.fetchEventsFromCalendar(calendarTitle: "Calendar")
break
case .restricted, .denied: break
}
}
func requestAccessToCalendar() {
eventStore.requestAccess(to: EKEntityType.event) { (accessGranted, error) in
self.fetchEventsFromCalendar(calendarTitle: "Calendar")
}
}
// MARK: Fetech Events from Calendar
func fetchEventsFromCalendar(calendarTitle: String) -> Void {
//PGAEventsCalendar
for calendar:EKCalendar in calendars! {
if calendar.title == calendarTitle {
let selectedCalendar = calendar
let startDate = NSDate(timeIntervalSinceNow: -60*60*24*180)
let endDate = NSDate(timeIntervalSinceNow: 60*60*24*180)
let predicate = eventStore.predicateForEvents(withStart: startDate as Date, end: endDate as Date, calendars: [selectedCalendar])
addedEvents = eventStore.events(matching: predicate) as [EKEvent]
print("addedEvents : \(addedEvents)")
}
}
}
Make sure to give the proper title of the calendar, because different calendars have different list of events, In my case calendar with title "Calendar" was having the required events list, before giving check for this:
if calendar.title == calendarTitle {
My first list was getting overrides by list from other calendar, so I used to get only few events which were not relevant to me.
Swift 3.0
let eventStore = EKEventStore()
let calendars = eventStore.calendars(for: .event)
for calendar in calendars {
if calendar.title == "Work" {
let oneMonthAgo = NSDate(timeIntervalSinceNow: -30*24*3600)
let oneMonthAfter = NSDate(timeIntervalSinceNow: +30*24*3600)
let predicate = eventStore.predicateForEvents(withStart: oneMonthAgo as Date, end: oneMonthAfter as Date, calendars: [calendar])
let events = eventStore.events(matching: predicate)
for event in events {
titles.append(event.title)
startDates.append(event.startDate as NSDate)
endDates.append(event.endDate as NSDate)
}
}
}
Related
I have 2 Controllers: TableViewController and ViewController. TableViewController is responsible for displaying all data, View Controller is responsible for creating new data.
Now I want to make it possible to edit the current data also in ViewController. When we click on data, we need to switch to the ViewController and replace all default values with the current values. When we change and click save, we go back to TableViewController, where we already see the change.
class OperationsViewController: UITableViewController {
// MARK: - Stored Properties
var transactions: Results<Transaction>!
var sections = [(date: Date, items: Results<Transaction>)]()
// MARK: - UITableViewController Methods
override func viewDidLoad() {
super.viewDidLoad()
transactions = realm.objects(Transaction.self)
}
override func viewWillAppear(_ animated: Bool) {
super .viewWillAppear(animated)
assembleGroupedTransactions()
tableView.reloadData()
}
}
// MARK: - Navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let indexPath = tableView.indexPathForSelectedRow {
let section = sections[indexPath.section]
let item = section.items[indexPath.row]
print(item)
if segue.identifier == "editOrDeleteOperationCell" {
let addTableViewController = segue.destination as! AddTableViewController
addTableViewController.defaultTransaction = item
}
}
}
}
// MARK: - User Interface
extension OperationsViewController {
#discardableResult private func assembleGroupedTransactions() -> Array<Any> {
// fetch all Items sorted by date
let results = realm.objects(Transaction.self).sorted(byKeyPath: "date", ascending: false)
sections = results
.map { item in
// get start of a day
return Calendar.current.startOfDay(for: item.date)
}
.reduce([]) { dates, date in
// unique sorted array of dates
return dates.last == date ? dates : dates + [date]
}
.compactMap { startDate -> (date: Date, items: Results<Transaction>) in
// create the end of current day
let endDate = Calendar.current.date(byAdding: .day, value: 1, to: startDate)!
// filter sorted results by a predicate matching current day
let items = results.filter("(date >= %#) AND (date < %#)", startDate, endDate)
// return a section only if current day is non-empty
return (date: startDate, items: items)
}
return sections
}
But when I trying to send current data to next ViewController I get error:
*** Terminating app due to uncaught exception 'RLMException', reason: 'Attempting to modify object outside of a write transaction - call beginWriteTransaction on an RLMRealm instance first.'
I guess that I have problem with Category. Look on my model:
class Transaction: Object {
#objc dynamic var controlStatus = 0
#objc dynamic private var privateCategory: String = Category.consumption.rawValue
var category: Category {
get { return Category(rawValue: privateCategory)! }
set { privateCategory = newValue.rawValue }
}
#objc dynamic var amount = "0"
#objc dynamic var date = Date()
#objc dynamic var note = ""
}
controlStatus needs for monitors the status of the transaction that will be needed in the future. Where 0 is the expense, 1 is the income.
The big problem I suppose is that I created categories by enum.
I need to change the arrays with categories depending on the controlStatus.
Now is this my model of Category:
indirect enum Category: String {
case income = "+"
case consumption = "-"
case salary = "salary"
case billingInterest = "billingInterest"
case partTimeJob = "partTimeJob"
etc.
}
extension Category: RawRepresentable {
typealias RawValue = String
init?(rawValue: RawValue) {
switch rawValue {
case "+": self = .income
case "-": self = .consumption
case "salary": self = .salary
case "billingInterest": self = .billingInterest
case "partTimeJob: self = .partTimeJob
case "pleasantFinds": self = .pleasantFinds
case "debtRepayment": self = .debtRepayment
case "noCategories": self = .noCategories
case "food": self = .food
etc.
default:
return nil
}
}
var rawValue: RawValue {
switch self {
case .salary:
return "salary"
case .billingInterest:
return "billingInterest"
case .partTimeJob:
return "partTimeJob"
case .pleasantFinds:
return "pleasantFinds"
case .debtRepayment:
return "debtRepayment"
case .noCategories:
return "noCategories"
case .food:
return "food"
case .cafesAndRestaurants:
return "cafesAndRestaurants"
etc.
}
}
}
You need to enclose your realm write transactions in write block
try realm.write({ () -> Void in
realm.add(object, update: true)
})
From Realm doc
try! realm.write {
realm.add(myDog)
}
I am trying to read all calendar events from the EventStore. The routine I use, works sometimes but not always.
func getCalendarEvents(_ anfangOpt: Date?, _ endeOpt: Date?) -> [EKEvent]? {
guard let anfang = anfangOpt, let ende = endeOpt else { return nil }
var events: [EKEvent]? = nil
let eventStore = EKEventStore()
eventStore.requestAccess( to: EKEntityType.event, completion: { _,_ in })
if EKEventStore.authorizationStatus(for: EKEntityType.event) == EKAuthorizationStatus.authorized {
var predicate: NSPredicate? = nil
predicate = eventStore.predicateForEvents(withStart: anfang, end: ende, calendars: nil)
if let aPredicate = predicate {
events = eventStore.events(matching: aPredicate)
}
}
return events
}
This function always returns the events. But they are sometimes incomplete. So that
for event in bereinigteEvents {
if dateInInterval(prüfdatum, start: event.startDate, ende: event.endDate) {
istimurlaub = true
if let zwischenname = event.title {
eventname = zwischenname
} else {
eventname = "n/a"
}
eventcalendar = event.calendar.title
trigger.append ("Auslöser: „" + eventname + "“ im Kalender „" + eventcalendar + "“")
}
}
sometimes crashes at the line "eventcalendar = event.calendar.title" and the error message that "nil" was unexpectedly found.
Thank you!
After the first answer I have changed the function, which gets the events to:
func getCalendarEvents(_ anfangOpt: Date?, _ endeOpt: Date?) -> [EKEvent]? {
guard let anfang = anfangOpt, let ende = endeOpt else { return nil }
var events: [EKEvent]? = nil
let eventStore = EKEventStore()
func fetchEvents() {
var predicate: NSPredicate? = nil
predicate = eventStore.predicateForEvents(withStart: anfang, end: ende, calendars: nil)
if let aPredicate = predicate {
events = eventStore.events(matching: aPredicate)
}
}
if EKEventStore.authorizationStatus(for: EKEntityType.event) == EKAuthorizationStatus.authorized {
fetchEvents()
} else {
eventStore.requestAccess( to: EKEntityType.event, completion: {(granted, error) in
if (granted) && (error == nil) {
fetchEvents()
}
})
}
return events
}
But it still crashes with "unexpectedly found nil" in "event.calendar.title".
I ended up using this
Swift 4 How to get all events from calendar?
routine to fetch the events.
The problem still occurs sometimes (!!): Occasionally "nil" is found in "event.calender.title", although it shouldn't be "nil"
The line
eventStore.requestAccess( to: EKEntityType.event, completion: { _,_ in })
is pointless because it works asynchronously. The result of the request is returned after the authorizationStatus check in the next line.
I recommend to first check the status. If the access is not granted ask for permission and perform the fetch. If it's granted perform the fetch directly. This can be accomplished by moving the code to fetch the events into a method.
Note:
It seems that you want to fetch the events when calling the method. Why do you declare start and end date as optional and check for nil?
Declare
func getCalendarEvents(_ anfang: Date, _ ende: Date) -> [EKEvent]? { ...
then you get notified at compile time whether a parameter is nil.
PS: Deutsche Parameternamen mit Umlauten sehen sehr lustig aus. (German parameter names with umlauts look pretty funny)
Problem was, that event.calendar is actually an optional (which I was not aware of).
if let eventZwischenCal = event.calendar {
eventcalendar = eventZwischenCal.title
} else {
eventcalendar = "n/a"
}
fixes the problem.
Is it possible to read Apple Watch move goal from HealthKit?
I can retrieve the Move value by using the Quantity Identifier HKQuantityTypeIdentifier.activeEnergyBurned. I could not find a similar identifier for the move goal.
//Declared globally
var healthStore: HKHealthStore?
func prepareHealthKit() {
guard HKHealthStore.isHealthDataAvailable() else {
return
}
var readTypes = Set<HKObjectType>()
readTypes.insert(HKObjectType.activitySummaryType())
healthStore = HKHealthStore()
healthStore!.requestAuthorization(toShare: nil, read: readTypes) { (isSuccess, error) in
/*
Assuming you know the following steps:
1. Start workout session: i.e. "HKWorkoutSession"
2. Wait for delegate: i.e "workoutSession(_:didChangeTo:from:date:)"
3. Start Query for Activity Summary in the delegate:
i.e our "startQueryForActivitySummary()"
*/
}
}
func startQueryForActivitySummary() {
func createPredicate() -> NSPredicate? {
let calendar = Calendar.autoupdatingCurrent
var dateComponents = calendar.dateComponents([.year, .month, .day],
from: Date())
dateComponents.calendar = calendar
let predicate = HKQuery.predicateForActivitySummary(with: dateComponents)
return predicate
}
let queryPredicate = createPredicate()
let query = HKActivitySummaryQuery(predicate: queryPredicate) { (query, summaries, error) -> Void in
if let summaries = summaries {
for summary in summaries {
let activeEnergyBurned = summary.activeEnergyBurned.doubleValue(for: HKUnit.kilocalorie())
let activeEnergyBurnedGoal = summary.activeEnergyBurnedGoal.doubleValue(for: HKUnit.kilocalorie())
let activeEnergyBurnGoalPercent = round(activeEnergyBurned/activeEnergyBurnedGoal)
print(activeEnergyBurnGoalPercent)
}
}
}
healthStore?.execute(query)
}
References:
https://crunchybagel.com/accessing-activity-rings-data-from-healthkit
https://developer.apple.com/documentation/healthkit/hkactivitysummary
https://developer.apple.com/documentation/healthkit/hkactivitysummaryquery
I got the answer. The move goal is accessible from HKActivitySummary.
You should request permission to read HKActivitySummaryType:
let activitySummaryType = HKActivitySummaryType.activitySummaryType()
let readDataTypes: Set<HKObjectType> = [activitySummaryType]
healthStore.requestAuthorization(toShare: nil, read: readDataTypes, completion: myCompletionHandler)
Then use HKActivitySummaryQuery to read the summary information
let query = HKActivitySummaryQuery(predicate: myPredicate) { (query, summaries, error) -> Void in
if error != nil {
fatalError("*** Did not return a valid error object. ***")
}
if let activitySummaries = summaries {
for summary in activitySummaries {
print(summary.activeEnergyBurnedGoal)
//do something with the summary here...
}
}
}
healthStore.execute(query)
Other activity summary data that is accessible from HKActivitySummary is available here.
I have an app that keeps track of monthly expenses. I have an Expense entity with a month attribute that keeps track of current month expense is created on. I would then display the expenses for each month in a table view as shown here. The user can only switch left and right only if there are expenses within the next or the last month
#IBAction func backMonthButtonPressed(sender: AnyObject) {
print("Back Button Pressed")
currentMonth = NSCalendar.currentCalendar().dateByAddingUnit(.Month, value: -1, toDate: currentMonth, options: [])!
if checkMonth(currentMonth) {
updateFetch()
setMonth()
} else {
currentMonth = NSCalendar.currentCalendar().dateByAddingUnit(.Month, value: 1, toDate: currentMonth, options: [])!
}
tableView.reloadData()
}
#IBAction func nextMonthButtonPressed(sender: AnyObject) {
print("Next Button Pressed")
currentMonth = NSCalendar.currentCalendar().dateByAddingUnit(.Month, value: 1, toDate: currentMonth, options: [])!
if checkMonth(currentMonth) {
updateFetch()
setMonth()
} else {
currentMonth = NSCalendar.currentCalendar().dateByAddingUnit(.Month, value: -1, toDate: currentMonth, options: [])!
}
tableView.reloadData()
}
func checkMonth(month : NSDate) -> Bool {
let app = UIApplication.sharedApplication().delegate as! AppDelegate
let context = app.managedObjectContext //scratch pad
let fetchRequest = NSFetchRequest(entityName: "Expense")
fetchRequest.predicate = NSPredicate(format: "month == %#", month.MonthYearDateFormatter())
let count = context.countForFetchRequest(fetchRequest, error: nil)
if count > 0 {
print("There are expenses for this month \(month.MonthYearDateFormatter()). Show expenses")
return true
} else {
print("There are no expenses for this month \(month.MonthYearDateFormatter()). Do Nothing")
return false
}
}
My problem is this, in the unlikely scenario that the user created an expense back in June and didn't create an expense in August. How can I let the user still see his/her expense back in August without skipping it. Any ideas?
I made some optimisation before elaboration:
#IBAction func backMonthButtonPressed(sender: AnyObject) {
self.processMonth(step: -1)
}
#IBAction func nextMonthButtonPressed(sender: AnyObject) {
self.processMonth(step: 1)
}
// a method uses almost the same code for both cases, so it was merged
func processMonth(step: Int) {
let direction = (step < 1 ? "Back" : "Next")
print("\(direction) Button Pressed")
currentMonth = NSCalendar.currentCalendar().dateByAddingUnit(.Month, value: step, toDate: currentMonth, options: [])!
//if checkMonth(currentMonth) {
// I wouldn't test this because it locks you out from seeing empty month.
updateFetch()
setMonth()
//}
tableView.reloadData()
}
An answer to what you've exactly asked:
If your data source for your UITableView is set properly, you should be able to go through empty months though
// changed return type from `Bool` to `void` as I suggested in the method not to test empty month, as it could be useless
func checkMonth(month : NSDate) {
let app = UIApplication.sharedApplication().delegate as! AppDelegate
let context = app.managedObjectContext //scratch pad
let fetchRequest = NSFetchRequest(entityName: "Expense")
fetchRequest.predicate = NSPredicate(format: "month == %#", month.MonthYearDateFormatter())
let count = context.countForFetchRequest(fetchRequest, error: nil)
if count > 0 {
print("There are expenses for this month \(month.MonthYearDateFormatter()). Show expenses")
} else {
print("There are no expenses for this month \(month.MonthYearDateFormatter()). Do Nothing")
// here you can make some additional actions, like seeting the empty table with "no expenses this month"
}
}
Anyway, as #Paulw11 noted, if your data source is not size-exhausting, you could rather fetch the data from your data-model at viewDidLoad/viewDidAppear for example and then to render each month according to the currentMonth variable (regarding what month a user currently see).
So as a result, you would call setMonth() method only in the load of your controller and each time a user changes a current month view.
With the help of #Paulw11 and #pedrouan, I was able to do what I wanted.
Fetch all expenses
func fetchExpenses() {
let app = UIApplication.sharedApplication().delegate as! AppDelegate
let context = app.managedObjectContext //scratch pad
let fetchRequest = NSFetchRequest(entityName: "Expense")
//Always Sort Budget by the date it's created
let sortDescriptor = NSSortDescriptor(key: "created", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
do {
let results = try context.executeFetchRequest(fetchRequest)
self.expenses = results as! [Expense]
} catch let err as NSError {
print(err.debugDescription)
}
}
Set constraints to first and last month to determine how far a user can navigate through months in viewDidLoad
//If array is not empty, set first and last month
if expenses.count > 0 {
guard let first = expenses.first?.month else {
return
}
firstMonth = first
guard let last = expenses.last?.month else {
return
}
lastMonth = last
}else {
//Set current month to be first and last
firstMonth = currentMonth.MonthYearDateFormatter()
lastMonth = currentMonth.MonthYearDateFormatter()
}
Limit user from going past first and last month
#IBAction func backMonthButtonPressed(sender: AnyObject) {
print("Back Button Pressed")
if currentMonth.MonthYearDateFormatter() != firstMonth {
self.processMonth(step: -1)
}
}
#IBAction func nextMonthButtonPressed(sender: AnyObject) {
print("Next Button Pressed")
if currentMonth.MonthYearDateFormatter() != lastMonth {
self.processMonth(step: 1)
}
}
Return all the expenses in current month and if there's none clear fetch and return empty table.
func updateFetch() {
setFetchResults()
do {
try self.fetchedResultsController.performFetch()
} catch {
let error = error as NSError
print("\(error), \(error.userInfo)")
}
}
func setFetchResults() {
let app = UIApplication.sharedApplication().delegate as! AppDelegate
let context = app.managedObjectContext //scratch pad
//Fetch Request
let fetchRequest = NSFetchRequest(entityName: "Expense")
let sortDescriptor = NSSortDescriptor(key: "created", ascending: false)
fetchRequest.predicate = NSPredicate(format: "month == %#", currentMonth.MonthYearDateFormatter())
fetchRequest.sortDescriptors = [sortDescriptor]
let count = context.countForFetchRequest(fetchRequest, error: nil)
let controller = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: ad.managedObjectContext , sectionNameKeyPath: section, cacheName: nil)
//If there is none, empty fetch request
if count == 0 {
print("There are no expenses for this month. Show nothing")
controller.fetchRequest.predicate = NSPredicate(value: false)
} else {
print("There are expenses for this month. Show expenses")
}
fetchedResultsController = controller
controller.delegate = self
}
With pedroruan's processMonth(), I was able to navigate through empty tableViews so that user can see that August is empty while still being able to go to June's month. Thanks guys.
I have a an entity in core data that represents a workout model. Each entity has a DayID attribute that represents which day the item falls into as shown in the image.
The code to create and save a specific item is shown below in Swift
#IBAction func doneButtonPressed(sender: AnyObject) {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let managedObjectContextCreation = appDelegate.managedObjectContext
let entityDescription = NSEntityDescription.entityForName("ExerciseItemModel", inManagedObjectContext: managedObjectContextCreation)
//Sunday
let exerciseItemtoAdd = ExerciseItemModel(entity: entityDescription!, insertIntoManagedObjectContext: managedObjectContextCreation)
exerciseItemtoAdd.dayID = dayName //DayName could be Wednesday
exerciseItemtoAdd.exerciseType = "Cardio"
exerciseItemtoAdd.exerciseName = self.exerciseNameTextField.text!
exerciseItemtoAdd.durationOrSets = durationLabelTextArea.text!
exerciseItemtoAdd.distanceOrReps = distanceLabelTextArea.text!
exerciseItemtoAdd.weight = ""
exerciseItemtoAdd.date = currentDate
appDelegate.saveContext() //Save the elements I just created.
let request: NSFetchRequest = NSFetchRequest(entityName: "ExerciseItemModel")
do {
_ = try managedObjectContextCreation.executeFetchRequest(request)
// success ...
} catch let error as NSError {
// failure
print("Fetch failed: \(error.localizedDescription)")
}
self.dismissViewControllerAnimated(true, completion: nil)
}
I can fetch items specific to a day e.g. Wednesday in cellForRowAtIndexPath using the following code:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let exerciseItem = fetchedResultController.objectAtIndexPath(indexPath) as! ExerciseItemModel
//Check if the DayID is the same as a specific WeekDay e.g. Wednesday
if exerciseItem.dayID == self.weekDayModel.dayName {
//All the code here
}
return Cell!
}
The problem I am hence facing is how do I specify the numbeOfRows in section function to only return the number of items related to a specific dayName. eg. I want only the number of items whose DayID is Wednesday.
At the moment the function return all the entities including those with other dayID's from Sunday to Saturday and hence distorts the TableView.
Here is my numberOfRowsInSection function:
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//let exerciseItem = fetchedResultController.
//if exerciseItem.dayID == self.weekDayModel.dayName {
//}
numberOfExerciseItems = fetchedResultController.sections![section].numberOfObjects
return fetchedResultController.sections![section].numberOfObjects
}
Any thoughts or help is greatly appreciated. :)
You want to add a predicate to your NSFetchRequest like so:
let request: NSFetchRequest = NSFetchRequest(entityName: "ExerciseItemModel")
request.predicate = NSPredicate("dayID == %#",self.weekDayModel.dayName)