Skip to content

Instantly share code, notes, and snippets.

//Add Framework: AudioToolbox.framework
#import <AudioToolbox/AudioToolbox.h>
//Obj-C:
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
//Swift:
AudioServicesPlayAlertSound(UInt32(kSystemSoundID_Vibrate));
AudioServicesPlaySystemSound(UInt32(kSystemSoundID_Vibrate))
// Objective-C
CKModifyRecordsOperation *modifyRecordsOperation = [[CKModifyRecordsOperation alloc] initWithRecordsToSave:records recordIDsToDelete:nil];
modifyRecordsOperation.atomic=NO;
modifyRecordsOperation.perRecordCompletionBlock = ^(CKRecord *record, NSError *error) {
//Swift 4.0
let modifyRecordsOperation = CKModifyRecordsOperation(recordsToSave: records, recordIDsToDelete: nil)
modifyRecordsOperation.isAtomic = false
modifyRecordsOperation.perRecordCompletionBlock = {(_ record: CKRecord, _ error: Error?) -> Void in } as? Void)
CKModifyRecordsOperation *modifyRecordsOperation = [[CKModifyRecordsOperation alloc] initWithRecordsToSave:records recordIDsToDelete:nil];
modifyRecordsOperation.atomic=NO;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//after changes
static NSString *CellIdentifier = @"Cella"; // change 1 - not the same with storyboard prototype cell
UITableViewCell *cell = (UITableViewCell *)[self.myTableView dequeueReusableCellWithIdentifier:CellIdentifier];
float screenW1 = [UIScreen mainScreen].bounds.size.width;
UIImage *cellImage;
UIButton *cellImageView;
UILabel *firstLabel, *secondLabel;
NSString *pathCircle;
if(!cell) {// change 2 - use initWithStyle reuseIdentifier - drawing, create frames just here
- (IBAction)startSync:(id)sender {
NSLog(@"startSync");
AppDelegate *appdelegate =(AppDelegate *)[UIApplication sharedApplication].delegate;
[appdelegate sync];
}
#pragma mark - QSCoreDataChangeManagerDelegate
- (void)changeManagerRequestsContextSave:(QSCoreDataChangeManager *)changeManager completion:(void (^)(NSError *))completion
{
if (debug==1) {
NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));
}
__block NSError *error = nil;
[self.managedObjectContext performBlockAndWait:^{
[self.managedObjectContext save:&error];
#pragma mark - ICLOUD
- (BOOL)iCloudAccountIsSignedIn {
if (debug==1) {
NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));
}
id token = [[NSFileManager defaultManager] ubiquityIdentityToken];
if (token) {
NSLog(@"** iCloud is SIGNED IN with token '%@' **", token);
return YES;
}
#pragma mark - SYNC
- (QSCloudKitSynchronizer *)synchronizer
{
if ([self iCloudEnabledByUser] && [self iCloudAccountIsSignedIn]) {
NSLog(@"** iCloud available SYNCHRONIZER! **");
if (!_synchronizer) {
_synchronizer = [QSCloudKitSynchronizer cloudKitSynchronizerWithContainerName:@"iCloud.com.SyncKitTest" managedObjectContext:self.managedObjectContext changeManagerDelegate:self];
}
}else{
NSLog(@"** iCloud not available **");
#pragma mark - Core Data stack
@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
- (NSURL *)applicationDocumentsDirectory {
// The directory the application uses to store the Core Data store file. This code uses a directory named "com.colourbox.cloudkittest.prueba" in the application's documents directory.
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
@IBAction func returned(from segue: UIStoryboardSegue) {
if (segue.identifier! == "UnwindFromSecondView") {
self.view.backgroundColor! = UIColor.orange
}
}