Skip to content

Instantly share code, notes, and snippets.

@mmuszynski
Last active August 18, 2017 18:02
Show Gist options
  • Save mmuszynski/9c55f3e8d29e46bc80a46483b04a94f4 to your computer and use it in GitHub Desktop.
Save mmuszynski/9c55f3e8d29e46bc80a46483b04a94f4 to your computer and use it in GitHub Desktop.
BSNDataController.m
-(NSMutableArray*)fetchFingeringsForNoteObject:(Note*)noteObject {
//slightly different, pulls the fingerings for a note OBJECT
//NSLog(@"Fetching fingering for note object with name: %@", noteObject.name);
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Fingering" inManagedObjectContext:[self managedObjectContext]];
[request setEntity:entity];
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[[self managedObjectContext] executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handle the error eventually.
}
//at this point, the array returned is the entire set of fingerings. this needs to be pared down to just the relevant objects
NSMutableArray *returnArray = [[NSMutableArray alloc] init];
for(Fingering *tempFingering in mutableFetchResults) {
if ([tempFingering.note isEqual:noteObject])
[returnArray addObject:tempFingering];
}
//NSLog(@"Found %d fingerings for note named %@", [returnArray count], noteObject.name);
return returnArray;
}
NotePickerView.swift
//Ask the data controller for the fingerings associated.
let dataController = BSNDataController()
guard let note = dataController.fetchNoteObjects(withName: foundPitch.description).firstObject as? Note else {
fatalError("Couldn't get the note object from the CoreData store.")
}
guard let fingerings = dataController.fetchFingerings(forNoteObject: note) as? [Fingering] else {
////Cannot convert value of type 'Note' to expected argument type 'Note!'
fatalError("No fingerings for the selected note.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment