Skip to content

Instantly share code, notes, and snippets.

View flexaddicted's full-sized avatar

Lorenzo B. flexaddicted

View GitHub Profile
@flexaddicted
flexaddicted / cd_additions_part1.m
Last active August 29, 2015 14:00
Extending NSManagedObject classes - Part 1
// NSManagedObject+CDAdditions.h
@interface NSManagedObject (CDAdditions)
+ (NSString *)CDAdditionsEntityName;
+ (instancetype)CDAdditionsInsertNewObjectIntoContext:(NSManagedObjectContext *)context;
@end
// NSManagedObject+CDAdditions.m
@implementation NSManagedObject (CDAdditions)
@flexaddicted
flexaddicted / cd_additions_part2.m
Last active August 29, 2015 14:00
Extending NSManagedObject classes - Part 2
// CDBaseManagedObject.h
@interface CDBaseManagedObject : NSManagedObject
+ (NSString *)entityName;
+ (instancetype)insertNewObjectIntoContext:(NSManagedObjectContext *)context;
@end
// CDBaseManagedObject.m
@implementation CDBaseManagedObject
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var tableView: UITableView!
private var swipeGestureStarted: Bool = false
private var selectedIndexPath: NSIndexPath?
override func viewDidLoad() {
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "MyCellIdentifier")
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if(editingStyle == UITableViewCellEditingStyle.Delete) {
// Here you should commit your editing
func tableView(tableView: UITableView, willBeginEditingRowAtIndexPath indexPath: NSIndexPath) {
self.swipeGestureStarted = true;
}
func tableView(tableView: UITableView, didEndEditingRowAtIndexPath indexPath: NSIndexPath) {
if(self.swipeGestureStarted) {
self.swipeGestureStarted = false
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var tableView: UITableView!
private var swipeGestureStarted: Bool = false
private var selectedIndexPath: NSIndexPath?
// ...
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.selectedIndexPath = indexPath
}
func tableView(tableView: UITableView, willBeginEditingRowAtIndexPath indexPath: NSIndexPath) {
self.swipeGestureStarted = true
}
func tableView(tableView: UITableView, didEndEditingRowAtIndexPath indexPath: NSIndexPath) {
if(self.swipeGestureStarted) {
self.swipeGestureStarted = false
self.tableView.selectRowAtIndexPath(self.selectedIndexPath, animated: true, scrollPosition: .None)
}
}