Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
import Combine
class MyDatabase: BindableObject {
let didChange = PassthroughSubject<MyDatabase, Never>()
var contacts: [Contact] = [
Contact(id: 1, name: "Anna"), Contact(id: 2, name: "Beto"),
Contact(id: 3, name: "Jack"), Contact(id: 4, name: "Sam")
] {
// only class types:
func myCast<MyClass: AnyObject>(value: AnyObject, type: MyClass.Type) -> MyClass? {
return value as? MyClass
}
// any type (class, struct, etc):
func myCast1<MyClass: Any>(value: Any, type: MyClass.Type) -> MyClass? {
return value as? MyClass
//
// JLNetworkActivityIndicatorManager.h
// EcoCr
//
// Created by Jack Lawrence on 6/27/12.
//
//
#import <Foundation/Foundation.h>
@jackhl
jackhl / gist:2782633
Created May 24, 2012 16:40
rdar://11520775
23-May-2012 08:52 PM Jack Lawrence:
Summary:
In iOS 5, the behavior of a UISplitViewController was changed such that instead of displaying a UIPopoverController in portrait orientation, the master view is "slid" like a drawer out from the left side of the display to cover a portion of the detail view. Appropriate callback methods have not been implemented to notify the delegate (in this case, the detail view controller) when the master controller was presented/will be presented/was dismissed/will be dismissed, where as they do exist (somewhat) for the UIPopoverController version in iOS 4.
You can see most obviously for the case of was presented/will be presented, the protocol only talks specifically about UIPopoverController objects so off the bat you can see that UIKit is missing some stuff. Furthermore, the documentation surrounding UISplitViewController hasn't been updated to reflect the fact that UIPopoverControllers are no longer used.
Steps to Reproduce:
In a detail view controller that conforms to U
@jackhl
jackhl / gist:2354122
Created April 10, 2012 20:08
core data fetch
NSString *currentChromosome = @"18";
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Gene"];
NSSortDescriptor *alphaSortNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"acronym" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:alphaSortNameDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"chromosome.identity = %@", currentChromosome];
[fetchRequest setPredicate:predicate];
NSError *fetchError = nil;
NSArray *genes = [[[DataManager sharedInstance] mainObjectContext] executeFetchRequest:fetchRequest error:&fetchError];
@jackhl
jackhl / MyObject.h
Last active October 2, 2015 02:38
Basic singleton
@interface MyObject : NSObject
@property (nonatomic, strong) NSMutableArray *myArray;
+ (MyObject *)sharedInstance;
@end
#import <Foundation/Foundation.h>
typedef enum {
kRotationDayA = 1,
kRotationDayB,
kRotationDayC,
kRotationDayD,
kRotationDayE,
kRotationDayF,
kRotationDayG
#import <Foundation/Foundation.h>
typedef enum {
kRotationDayA,
kRotationDayB,
kRotationDayC,
kRotationDayD,
kRotationDayE,
kRotationDayF,
kRotationDayG
- (void) flipToGameScreen:(NSInteger *)aMode aLevel:(NSInteger*)aLevel
{
//NSInteger *myMode = aMode; you don't need to do this... you can just directly use aLevel and aMode
//NSInteger *myLevel = aLevel;
GameScreenViewController *aGameScreenView = [[GameScreenViewController alloc] initWithNibName:@"GameScreen" mode:aMode level:aLevel bundle:nil];
[self setGameScreenViewController:aGameScreenView];
[aGameScreenView release];
gameScreenViewController.view.frame =[[UIScreen mainScreen] applicationFrame];