Permalink
Browse files

Initial commit

  • Loading branch information...
keithpitt committed Aug 19, 2011
0 parents commit c5fcc40e3b2879efdf87032b9964e879556b2f82
Showing with 1,018 additions and 0 deletions.
  1. +8 −0 .gitignore
  2. +22 −0 Classes/DKPropertyList.h
  3. +123 −0 Classes/DKPropertyList.m
  4. +350 −0 DKPropertyList.xcodeproj/project.pbxproj
  5. +1 −0 External/Cedar-iPhone.framework/Cedar-iPhone
  6. +1 −0 External/Cedar-iPhone.framework/Headers
  7. +1 −0 External/Cedar-iPhone.framework/Resources
  8. BIN External/Cedar-iPhone.framework/Versions/A/Cedar-iPhone
  9. +6 −0 External/Cedar-iPhone.framework/Versions/A/Headers/CDRColorizedReporter.h
  10. +36 −0 External/Cedar-iPhone.framework/Versions/A/Headers/CDRExampleBase.h
  11. +13 −0 External/Cedar-iPhone.framework/Versions/A/Headers/CDRExampleDetailsViewController.h
  12. +12 −0 External/Cedar-iPhone.framework/Versions/A/Headers/CDRExampleParent.h
  13. +9 −0 External/Cedar-iPhone.framework/Versions/A/Headers/CDRExampleReporter.h
  14. +7 −0 External/Cedar-iPhone.framework/Versions/A/Headers/CDRExampleReporterViewController.h
  15. +7 −0 External/Cedar-iPhone.framework/Versions/A/Headers/CDRFunctions.h
  16. +32 −0 External/Cedar-iPhone.framework/Versions/A/Headers/CDRSharedExampleGroupPool.h
  17. +53 −0 External/Cedar-iPhone.framework/Versions/A/Headers/CDRSpec.h
  18. +7 −0 External/Cedar-iPhone.framework/Versions/A/Headers/Cedar.h
  19. +10 −0 External/Cedar-iPhone.framework/Versions/A/Headers/CedarApplicationDelegate.h
  20. +16 −0 External/Cedar-iPhone.framework/Versions/A/Headers/SpecHelper.h
  21. +1 −0 External/Cedar-iPhone.framework/Versions/Current
  22. +41 −0 External/Expecta/EXPExpect.h
  23. +8 −0 External/Expecta/EXPMatcherHelpers.h
  24. +7 −0 External/Expecta/EXPMatchers+toBeFalsy.h
  25. +7 −0 External/Expecta/EXPMatchers+toBeIdenticalTo.h
  26. +11 −0 External/Expecta/EXPMatchers+toBeInstanceOf.h
  27. +9 −0 External/Expecta/EXPMatchers+toBeKindOf.h
  28. +9 −0 External/Expecta/EXPMatchers+toBeNil.h
  29. +9 −0 External/Expecta/EXPMatchers+toBeSubclassOf.h
  30. +7 −0 External/Expecta/EXPMatchers+toBeTruthy.h
  31. +9 −0 External/Expecta/EXPMatchers+toContain.h
  32. +9 −0 External/Expecta/EXPMatchers+toEqual.h
  33. +13 −0 External/Expecta/EXPMatchers.h
  34. +15 −0 External/Expecta/EXPUnsupportedObject.h
  35. +20 −0 External/Expecta/Expecta.h
  36. +38 −0 External/Expecta/ExpectaSupport.h
  37. +9 −0 External/Expecta/NSObject+Expecta.h
  38. +12 −0 External/Expecta/NSValue+Expecta.h
  39. BIN External/Expecta/libExpecta-ios-universal.a
  40. +36 −0 Specs/Specs-Info.plist
  41. +14 −0 Specs/Specs-Prefix.pch
  42. +2 −0 Specs/en.lproj/InfoPlist.strings
  43. +18 −0 Specs/main.m
@@ -0,0 +1,8 @@
+build
+*.pbxuser
+*.mode1v3
+.DS_Store
+pkg
+*.xcworkspace
+xcuserdata
+contents.xcworkspacedata
@@ -0,0 +1,22 @@
+//
+// DKPropertyList.m
+// DiscoKit
+//
+// Created by Keith Pitt on 12/06/11.
+// Copyright 2011 Mostly Disco. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface DKPropertyList : NSObject {
+
+ NSString *_plistPath;
+ NSArray *_properties;
+
+}
+
+- (void)save;
+- (void)loadFromDictionary:(NSMutableDictionary*)dict;
+- (void)saveToDictionary:(NSMutableDictionary*)dict;
+
+@end
@@ -0,0 +1,123 @@
+//
+// DKPropertyList.m
+// DiscoKit
+//
+// Created by Keith Pitt on 12/06/11.
+// Copyright 2011 Mostly Disco. All rights reserved.
+//
+
+#import "DKPropertyList.h"
+#import "objc/runtime.h"
+
+@implementation DKPropertyList
+
+- (id)init {
+
+ if ((self = [super init])) {
+
+ // Figure out the ~/Documents folder for the iPhone. We can only write stuff here.
+ NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
+ _plistPath = [rootPath stringByAppendingString:@"/UserProperties.plist"];
+ [_plistPath retain];
+
+ // If the plist doesn't exist, copy the bundled one with app the to ~/Documents
+ // directory (so we can write back to it).
+ if (![[NSFileManager defaultManager] fileExistsAtPath:_plistPath]) {
+
+ NSString *bundled = [[NSBundle mainBundle] pathForResource:@"UserProperties" ofType:@"plist"];
+
+ // If we have a bundled version?
+ if(bundled) {
+ NSLog(@"%@", bundled);
+
+ NSError *error = nil;
+ [[NSFileManager defaultManager] copyItemAtPath:bundled toPath: _plistPath error:&error];
+
+ // TODO: Do something with the error, possibly.
+ } else {
+
+ // Create an empty file
+ NSDictionary *blankDictionary = [NSDictionary dictionary];
+ [blankDictionary writeToFile:_plistPath atomically:YES];
+
+ }
+
+ }
+
+ // Extract the data into a dictionary.
+ NSMutableDictionary *temp = [[NSMutableDictionary alloc] initWithContentsOfFile: _plistPath];
+
+ // Load the properties of the class into an array
+ NSMutableArray *collection = [NSMutableArray array];
+
+ unsigned int outCount, i;
+ objc_property_t *properties = class_copyPropertyList([self class], &outCount);
+
+ for (i = 0; i < outCount; i++) {
+ objc_property_t property = properties[i];
+ [collection addObject:[NSString stringWithCString:property_getName(property)
+ encoding:NSASCIIStringEncoding]];
+ }
+
+ _properties = collection;
+ [_properties retain];
+
+ // Load them into the current class
+ [self loadFromDictionary:temp];
+
+ [temp release];
+
+ }
+
+ return self;
+
+}
+
+- (void)save {
+
+ // Extract the data into a dictionary.
+ NSMutableDictionary *temp = [[NSMutableDictionary alloc] initWithContentsOfFile: _plistPath];
+
+ [self saveToDictionary:temp];
+
+ // Save that shit.
+ [temp writeToFile:_plistPath atomically:YES];
+
+ // Cleanup
+ [temp release];
+
+}
+
+- (void)loadFromDictionary:(NSMutableDictionary*)dict {
+
+ // Load values from the dictionary
+ for (NSString *property in _properties)
+ [self setValue:[dict objectForKey:property] forKey:property];
+
+}
+
+- (void)saveToDictionary:(NSMutableDictionary*)dict {
+
+ // Re-set it back to the dictionary.
+ for (NSString *property in _properties) {
+ id value = [self valueForKey:property];
+ if (value)
+ [dict setObject:value forKey:property];
+ }
+
+}
+
+- (void)dealloc {
+
+ // Cleanup
+ for (NSString *property in _properties)
+ [self setValue:nil forKey:property];
+
+ [_properties release];
+ [_plistPath release];
+
+ [super dealloc];
+
+}
+
+@end
Oops, something went wrong.

0 comments on commit c5fcc40

Please sign in to comment.