Skip to content

Instantly share code, notes, and snippets.

@3lvis
3lvis / Cell.swift
Created September 18, 2015 14:06
Cell.swift
import UIKit
class SlotCell: UITableViewCell {
static let Identifier = "SlotCellIdentifier"
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.contentView.backgroundColor = UIColor(hex: "28C787")
}
@3lvis
3lvis / Controller.swift
Created September 18, 2015 14:06
Controller.swift
import UIKit
import DATASource
class SlotsController: UITableViewController {
var networking: NetworkingClient
// MARK - Getters
lazy var dataSource: DATASource = {
let dataSource = DATASource(tableView: self.tableView, fetchRequest: Slot.request(), sectionName: nil, cellIdentifier: SlotCell.Identifier, mainContext: self.networking.data.mainContext, configuration: { cell, item, indexPath in
@3lvis
3lvis / ManagedObject.swift
Created September 18, 2015 14:07
ManagedObject.swift
import CoreData
@objc(Slot)
public class Slot: _Slot {
static func request() -> NSFetchRequest {
let request = NSFetchRequest(entityName: Slot.entityName())
request.sortDescriptors = [NSSortDescriptor(key: "startTime", ascending: true)]
return request
}
[
{
"__v":0,
"name":"test 2",
"createdAt":"01.10.2015 19:11",
"latitude":"",
"longitude":"",
"_id":"560d9f051f2c3ec00ed756c8"
},
{
import Foundation
protocol Syncable {
static func sync(dictionary: [Dictionary<String, AnyObject>])
}
extension Syncable {
static func sync(dictionary: [Dictionary<String, AnyObject>]) {
}
@3lvis
3lvis / .gitignore
Created June 22, 2013 11:15
Xcode .gitignore
# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3

Accessing an API using CoreData's NSIncrementalStore

Note: the original location of this article is on my blog, however, it is posted here too for better readability.

In this article, we will see how to use Core Data for accessing your API. We will use the Bandcamp API as our running example. I've only been experimenting with this code for a few days, so there might be mistakes in there.

//
// SKShapeNode+Utility.m
// Dynamics
//
// Created by Jonathan Wight on 6/14/13.
// Copyright (c) 2013 toxicsoftware. All rights reserved.
//
#import "SKShapeNode+Utility.h"
@3lvis
3lvis / gist:6777799
Last active December 24, 2015 09:29
Screenshot
+ (UIImage *)screenshot
{
CGSize imageSize = CGSizeZero;
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsPortrait(orientation)) {
imageSize = [UIScreen mainScreen].bounds.size;
} else {
imageSize = CGSizeMake([UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
}
let remoteItems = localPrimaryKey
let localRelationship = self.valueForKey(relationship.name)
let localItems = localRelationship?.valueForKey(entity.sync_localPrimaryKey()) as? NSArray ?? NSArray()
let intersection = NSMutableSet(array: remoteItems as [AnyObject])
intersection.intersectSet(Set(arrayLiteral: localItems))
let updatedItems = intersection.allObjects
let deletedItems = localItems.mutableCopy()
deletedItems.removeObjectsInArray(remoteItems as [AnyObject])