forked from yapstudios/YapDatabase
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
234 changed files
with
11,684 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// AppDelegate.h | ||
// List | ||
// | ||
// Created by Denis Hennessy on 06/04/2015. | ||
// Copyright (c) 2015 Peer Assembly. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface AppDelegate : NSObject <NSApplicationDelegate> | ||
|
||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// AppDelegate.m | ||
// List | ||
// | ||
// Created by Denis Hennessy on 06/04/2015. | ||
// Copyright (c) 2015 Peer Assembly. All rights reserved. | ||
// | ||
|
||
#import "AppDelegate.h" | ||
#import "Database.h" | ||
|
||
@interface AppDelegate () | ||
|
||
@end | ||
|
||
@implementation AppDelegate | ||
|
||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { | ||
[Database sharedInstance]; | ||
} | ||
|
||
- (void)applicationWillTerminate:(NSNotification *)aNotification { | ||
// Insert code here to tear down your application | ||
} | ||
|
||
@end |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Database.h | ||
// List | ||
// | ||
// Created by Denis Hennessy on 06/04/2015. | ||
// Copyright (c) 2015 Peer Assembly. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "YapDatabase.h" | ||
#import "YapDatabaseView.h" | ||
|
||
extern NSString *const UIDatabaseConnectionWillUpdateNotification; | ||
extern NSString *const UIDatabaseConnectionDidUpdateNotification; | ||
extern NSString *const kNotificationsKey; | ||
|
||
@interface Database : NSObject <NSFilePresenter> { | ||
NSFileCoordinator *_fileCoordinator; | ||
} | ||
|
||
@property (nonatomic, readonly) NSURL *databaseURL; | ||
@property (nonatomic, readonly) YapDatabase *database; | ||
@property (nonatomic, readonly) YapDatabaseConnection *uiConnection; | ||
@property (nonatomic, readonly) YapDatabaseConnection *bgConnection; | ||
|
||
+ (Database *)sharedInstance; | ||
+ (NSString *)newUuid; | ||
|
||
- (void)reconnect; | ||
- (void)invalidateCaches; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// | ||
// Database.m | ||
// List | ||
// | ||
// Created by Denis Hennessy on 06/04/2015. | ||
// Copyright (c) 2015 Peer Assembly. All rights reserved. | ||
// | ||
|
||
#import "Database.h" | ||
|
||
NSString *const UIDatabaseConnectionWillUpdateNotification = @"UIDatabaseConnectionWillUpdateNotification"; | ||
NSString *const UIDatabaseConnectionDidUpdateNotification = @"UIDatabaseConnectionDidUpdateNotification"; | ||
NSString *const kNotificationsKey = @"notifications"; | ||
|
||
static NSOperationQueue *_presentedItemOperationQueue; | ||
|
||
@implementation Database | ||
|
||
+ (NSString *)newUuid { | ||
return [[NSUUID UUID] UUIDString]; | ||
} | ||
|
||
+ (Database *)sharedInstance { | ||
static Database *_sharedInstance = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
_presentedItemOperationQueue = [[NSOperationQueue alloc] init]; | ||
_sharedInstance = [[Database alloc] init]; | ||
}); | ||
|
||
return _sharedInstance; | ||
} | ||
|
||
- (id)init { | ||
if (self = [super init]) { | ||
NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
NSURL *url = [[fileManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask] lastObject]; | ||
NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier]; | ||
NSURL *folder = [url URLByAppendingPathComponent:bundleID]; | ||
[fileManager createDirectoryAtURL:folder withIntermediateDirectories:YES attributes:nil error:NULL]; | ||
_databaseURL = [folder URLByAppendingPathComponent:@"List.sqlite"]; | ||
|
||
[NSFileCoordinator addFilePresenter:self]; | ||
_fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:self]; | ||
[self openDatabase]; | ||
} | ||
return self; | ||
} | ||
|
||
#pragma mark - NSFilePresenter | ||
|
||
- (NSURL *)presentedItemURL { | ||
return _databaseURL; | ||
} | ||
|
||
- (NSOperationQueue *)presentedItemOperationQueue { | ||
return _presentedItemOperationQueue; | ||
} | ||
|
||
- (void)invalidateCaches { | ||
[_bgConnection flushMemoryWithFlags:YapDatabaseConnectionFlushMemoryFlags_Caches]; | ||
[_uiConnection endLongLivedReadTransaction]; | ||
[_uiConnection flushMemoryWithFlags:YapDatabaseConnectionFlushMemoryFlags_Caches]; | ||
[_uiConnection beginLongLivedReadTransaction]; | ||
} | ||
|
||
#pragma mark - Implementation | ||
|
||
- (void)openDatabase { | ||
NSError *error = nil; | ||
[_fileCoordinator coordinateWritingItemAtURL:_databaseURL options:0 error:&error byAccessor:^(NSURL *newURL) { | ||
NSLog(@"DB: %@", newURL.path); | ||
_database = [[YapDatabase alloc] initWithPath:newURL.path]; | ||
if (!_database) { | ||
NSLog(@"Fatal: unable to create/open database"); | ||
} | ||
_bgConnection = [_database newConnection]; | ||
_bgConnection.objectCacheLimit = 400; | ||
_bgConnection.metadataCacheEnabled = NO; | ||
|
||
_uiConnection = [_database newConnection]; | ||
_uiConnection.objectCacheLimit = 400; | ||
_uiConnection.metadataCacheEnabled = NO; | ||
#if DEBUG | ||
_uiConnection.permittedTransactions = YDB_SyncReadTransaction | YDB_MainThreadOnly; | ||
#endif | ||
[_uiConnection enableExceptionsForImplicitlyEndingLongLivedReadTransaction]; | ||
[_uiConnection beginLongLivedReadTransaction]; | ||
|
||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yapDatabaseModified:) | ||
name:YapDatabaseModifiedNotification | ||
object:_database]; | ||
}]; | ||
} | ||
|
||
- (void)reconnect { | ||
[[NSNotificationCenter defaultCenter] removeObserver:self]; | ||
_bgConnection = nil; | ||
_uiConnection = nil; | ||
_database = nil; | ||
|
||
[self openDatabase]; | ||
} | ||
|
||
- (void)yapDatabaseModified:(NSNotification *)ignored { | ||
[[NSNotificationCenter defaultCenter] postNotificationName:UIDatabaseConnectionWillUpdateNotification object:self]; | ||
NSArray *notifications = [_uiConnection beginLongLivedReadTransaction]; | ||
NSDictionary *userInfo = @{ kNotificationsKey : notifications }; | ||
[[NSNotificationCenter defaultCenter] postNotificationName:UIDatabaseConnectionDidUpdateNotification object:self userInfo:userInfo]; | ||
} | ||
|
||
|
||
@end |
58 changes: 58 additions & 0 deletions
58
Examples/List/List/Images.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "mac", | ||
"size" : "16x16", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "16x16", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "32x32", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "32x32", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "128x128", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "128x128", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "256x256", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "256x256", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "512x512", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "512x512", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIconFile</key> | ||
<string></string> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.peerassembly.$(PRODUCT_NAME:rfc1034identifier)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSMinimumSystemVersion</key> | ||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string> | ||
<key>NSHumanReadableCopyright</key> | ||
<string>Copyright © 2015 Peer Assembly. All rights reserved.</string> | ||
<key>NSMainStoryboardFile</key> | ||
<string>Main</string> | ||
<key>NSPrincipalClass</key> | ||
<string>NSApplication</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// ViewController.h | ||
// List | ||
// | ||
// Created by Denis Hennessy on 06/04/2015. | ||
// Copyright (c) 2015 Peer Assembly. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface ViewController : NSViewController | ||
|
||
@property (weak) IBOutlet NSButton *breakfastButton; | ||
@property (weak) IBOutlet NSButton *lunchButton; | ||
@property (weak) IBOutlet NSButton *dinnerButton; | ||
@property (weak) IBOutlet NSTextField *snapshotTextField; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// ViewController.m | ||
// List | ||
// | ||
// Created by Denis Hennessy on 06/04/2015. | ||
// Copyright (c) 2015 Peer Assembly. All rights reserved. | ||
// | ||
|
||
#import "ViewController.h" | ||
#import "Database.h" | ||
|
||
@implementation ViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
[self configureUI]; | ||
|
||
[[NSNotificationCenter defaultCenter] addObserver:self | ||
selector:@selector(databaseConnectionDidUpdate:) | ||
name:UIDatabaseConnectionDidUpdateNotification | ||
object:nil]; | ||
} | ||
|
||
- (void)databaseConnectionDidUpdate:(NSNotification *)notification { | ||
NSLog(@"databaseConnectionDidUpdate"); | ||
[self configureUI]; | ||
} | ||
|
||
- (void)configureUI { | ||
[[Database sharedInstance].uiConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { | ||
[_breakfastButton setState:[[transaction objectForKey:@"breakfast" inCollection:@"meals"] integerValue]]; | ||
[_lunchButton setState:[[transaction objectForKey:@"lunch" inCollection:@"meals"] integerValue]]; | ||
[_dinnerButton setState:[[transaction objectForKey:@"dinner" inCollection:@"meals"] integerValue]]; | ||
}]; | ||
_snapshotTextField.stringValue = [NSString stringWithFormat:@"%llu", [[Database sharedInstance].uiConnection snapshot]]; | ||
} | ||
|
||
- (IBAction)mealTapped:(NSButton *)sender { | ||
NSString *meal = nil; | ||
if (sender == _breakfastButton) { | ||
meal = @"breakfast"; | ||
} else if (sender == _lunchButton) { | ||
meal = @"lunch"; | ||
} else { | ||
meal = @"dinner"; | ||
} | ||
[[Database sharedInstance].bgConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { | ||
[transaction setObject:[NSNumber numberWithInteger:sender.state] forKey:meal inCollection:@"meals"]; | ||
}]; | ||
|
||
} | ||
|
||
- (IBAction)refreshTapped:(id)sender { | ||
[[Database sharedInstance] invalidateCaches]; | ||
// [[Database sharedInstance] reconnect]; | ||
[self configureUI]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// main.m | ||
// List | ||
// | ||
// Created by Denis Hennessy on 06/04/2015. | ||
// Copyright (c) 2015 Peer Assembly. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
int main(int argc, const char * argv[]) { | ||
return NSApplicationMain(argc, argv); | ||
} |
Oops, something went wrong.