forked from shaojiankui/JKCategories
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NSPersistentStoreCoordinator+Custom NSString+Pinyin NSUserDefaults+iCloudSync CAAnimation+Blocks CAAnimation+EasingEquations CAMediaTimingFunction+AdditionalEquations CAShapeLayer+UIBezierPath CATransaction+AnimateWithDuration UIApplication+ApplicationSize UIApplication+NetworkActivityIndicator UIApplication+Permissions UIDevice+PasscodeStatus UIImage+BetterFace UIImage+Vector UIImageView+BetterFace UIImageView+FaceAwareFill UIImageView+GeometryConversion UIImageView+Letters UIImageView+Reflect UIResponder+FirstResponder UIScrollView+APParallaxHeader UIScrollView+Direction UITextField+History UITextField+Shake UITextView+PinchZoom UIView+Visuals UIView+draggable UIViewController+ScrollingStatusBar UIViewController+StoreKit UIWebVIew+SwipeGesture UIWebView+MetaParser
- Loading branch information
Jakey
authored and
Jakey
committed
Jun 20, 2015
1 parent
729cd11
commit 3af67c9
Showing
96 changed files
with
6,416 additions
and
35 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
Categories/CoreData/NSManagedObject/NSManagedObject+DictionaryExport.h
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,37 @@ | ||
// | ||
// NSManagedObject+KRDictionaryExport | ||
// | ||
// Created by Kishyr Ramdial on 2012/08/21. | ||
// Copyright (c) 2012 Kishyr Ramdial. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
|
||
// https://github.com/kishyr/KRDictionaryExport | ||
|
||
// A category for NSManagedObject which exports a CoreData object into an NSDictionary, including all its relationships. The NSDictionary created is formatted for easy JSON-conversion using something like JSONKit or NSJSONSerialization. | ||
|
||
#import <CoreData/CoreData.h> | ||
|
||
@interface NSManagedObject (DictionaryExport) | ||
|
||
- (NSDictionary *)asDictionary; | ||
//http://stackoverflow.com/questions/5664423/storing-nsmanagedobject-in-a-dictionary-nsdictionary | ||
- (NSDictionary *)Dictionary; | ||
@end |
86 changes: 86 additions & 0 deletions
86
Categories/CoreData/NSManagedObject/NSManagedObject+DictionaryExport.m
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,86 @@ | ||
// | ||
// NSManagedObject+KRDictionaryExport | ||
// | ||
// Created by Kishyr Ramdial on 2012/08/21. | ||
// Copyright (c) 2012 Kishyr Ramdial. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import <objc/runtime.h> | ||
#import "NSManagedObject+DictionaryExport.h" | ||
|
||
@implementation NSManagedObject (DictionaryExport) | ||
|
||
- (NSDictionary *)asDictionary { | ||
unsigned int count; | ||
|
||
objc_property_t *properties = class_copyPropertyList([self class], &count); | ||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; | ||
|
||
for (int i = 0; i<count; i++) { | ||
objc_property_t property = properties[i]; | ||
NSString *name = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding]; | ||
id obj = [self valueForKey:name]; | ||
if (obj) { | ||
|
||
if (![[obj class] isSubclassOfClass:[NSData class]]) { | ||
if ([[obj class] isSubclassOfClass:[NSManagedObject class]]) { | ||
|
||
NSArray *relationships = [[obj entity] relationshipsWithDestinationEntity:[self entity]]; | ||
if ([relationships count] > 0) { | ||
NSString *relName = [[relationships objectAtIndex:0] name]; | ||
|
||
NSDictionary *namedRelationships = [[obj entity] relationshipsByName]; | ||
BOOL isParent = [[[(NSRelationshipDescription *)[namedRelationships objectForKey:relName] destinationEntity] name] isEqualToString:NSStringFromClass([self class])]; | ||
if (!isParent) | ||
[dictionary setObject:[(NSManagedObject *)obj asDictionary] forKey:name]; | ||
} | ||
else { | ||
[dictionary setObject:[(NSManagedObject *)obj asDictionary] forKey:name]; | ||
} | ||
} | ||
else if ([[obj class] isSubclassOfClass:[NSSet class]]) { | ||
if ([obj count] > 0) { | ||
NSArray *array = [(NSSet *)obj allObjects]; | ||
NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:[array count]]; | ||
for (id o in array) | ||
[mutableArray addObject:[(NSManagedObject *)o asDictionary]]; | ||
|
||
[dictionary setObject:[NSArray arrayWithArray:mutableArray] forKey:name]; | ||
} | ||
} | ||
else if ([[obj class] isSubclassOfClass:[NSDate class]]) { | ||
[dictionary setObject:[obj description] forKey:name]; | ||
} | ||
else { | ||
[dictionary setObject:obj forKey:name]; | ||
} | ||
} | ||
} | ||
} | ||
free(properties); | ||
|
||
return dictionary; | ||
} | ||
- (NSDictionary *)Dictionary{ | ||
NSArray *keys = [[[self entity] attributesByName] allKeys]; | ||
NSDictionary *dict = [self dictionaryWithValuesForKeys:keys]; | ||
return dict; | ||
} | ||
@end |
17 changes: 17 additions & 0 deletions
17
Categories/CoreData/NSPersistentStoreCoordinator/NSPersistentStoreCoordinator+Custom.h
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,17 @@ | ||
// | ||
// NSPersistentStoreCoordinator+Custom.h | ||
// CocoaPodsManager | ||
// | ||
// Created by Andrei Zaharia on 9/18/13. | ||
// Copyright (c) 2013 Andy. All rights reserved. | ||
// | ||
|
||
#import <CoreData/CoreData.h> | ||
|
||
@interface NSPersistentStoreCoordinator (Custom) | ||
|
||
+ (void) setDataModelName: (NSString *) name withStoreName: (NSString *) storeFileName; | ||
+ (NSPersistentStoreCoordinator *) sharedPersisntentStoreCoordinator; | ||
+ (void) setNewPresistentStore: (NSPersistentStoreCoordinator *) store; | ||
|
||
@end |
62 changes: 62 additions & 0 deletions
62
Categories/CoreData/NSPersistentStoreCoordinator/NSPersistentStoreCoordinator+Custom.m
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,62 @@ | ||
// | ||
// NSPersistentStoreCoordinator+Custom.m | ||
// CocoaPodsManager | ||
// | ||
// Created by Andrei Zaharia on 9/18/13. | ||
// Copyright (c) 2013 Andy. All rights reserved. | ||
// | ||
|
||
#import "NSPersistentStoreCoordinator+Custom.h" | ||
|
||
@implementation NSPersistentStoreCoordinator (Custom) | ||
|
||
static NSPersistentStoreCoordinator *_sharedPersistentStore = nil; | ||
static NSString *_dataModelName = nil; | ||
static NSString *_storeFileName = nil; | ||
|
||
+ (NSString *)applicationDocumentsDirectory { | ||
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; | ||
} | ||
|
||
+ (void) setDataModelName: (NSString *) name withStoreName: (NSString *) storeFileName { | ||
_dataModelName = name; | ||
_storeFileName = storeFileName; | ||
} | ||
|
||
+(NSPersistentStoreCoordinator *) sharedPersisntentStoreCoordinator | ||
{ | ||
NSAssert(_dataModelName, @"Core Data model name has not been set. Use [NSPersistentStoreCoordinator setDataModelName:]."); | ||
|
||
if (!_sharedPersistentStore) { | ||
NSString *storePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent: _storeFileName]; | ||
NSURL *storeUrl = [NSURL fileURLWithPath:storePath]; | ||
|
||
NSBundle *bundle = [NSBundle mainBundle]; | ||
NSString *resourcePath = [bundle resourcePath]; | ||
NSString *modelFileName = [_dataModelName stringByAppendingPathExtension:@"momd"]; | ||
NSString *modelPath = [resourcePath stringByAppendingPathComponent: modelFileName]; | ||
|
||
NSURL *modelUrl = [NSURL fileURLWithPath: modelPath]; | ||
|
||
NSManagedObjectModel *_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL: modelUrl]; | ||
|
||
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @(YES), | ||
NSInferMappingModelAutomaticallyOption : @(YES)}; | ||
|
||
NSError *error; | ||
_sharedPersistentStore = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: _managedObjectModel]; | ||
if (![_sharedPersistentStore addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) { | ||
NSLog(@"Unresolved error %@, %@", error, [error userInfo]); | ||
abort(); | ||
} | ||
} | ||
|
||
return _sharedPersistentStore; | ||
} | ||
|
||
+ (void) setNewPresistentStore: (NSPersistentStoreCoordinator *) store | ||
{ | ||
_sharedPersistentStore = store; | ||
} | ||
|
||
@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,22 @@ | ||
// | ||
// NSString+Pinyin.h | ||
// Snowball | ||
// | ||
// Created by croath on 11/11/13. | ||
// Copyright (c) 2013 Snowball. All rights reserved. | ||
// | ||
// https://github.com/croath/NSString-Pinyin | ||
// the Chinese Pinyin string of the nsstring | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSString (Pinyin) | ||
|
||
- (NSString*)pinyinWithPhoneticSymbol; | ||
- (NSString*)pinyin; | ||
- (NSArray*)pinyinArray; | ||
- (NSString*)pinyinWithoutBlank; | ||
- (NSArray*)pinyinInitialsArray; | ||
- (NSString*)pinyinInitialsString; | ||
|
||
@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,58 @@ | ||
// | ||
// NSString+Pinyin.m | ||
// Snowball | ||
// | ||
// Created by croath on 11/11/13. | ||
// Copyright (c) 2013 Snowball. All rights reserved. | ||
// | ||
|
||
#import "NSString+Pinyin.h" | ||
|
||
@implementation NSString (Pinyin) | ||
|
||
- (NSString*)pinyinWithPhoneticSymbol{ | ||
NSMutableString *pinyin = [NSMutableString stringWithString:self]; | ||
CFStringTransform((__bridge CFMutableStringRef)(pinyin), NULL, kCFStringTransformMandarinLatin, NO); | ||
return pinyin; | ||
} | ||
|
||
- (NSString*)pinyin{ | ||
NSMutableString *pinyin = [NSMutableString stringWithString:[self pinyinWithPhoneticSymbol]]; | ||
CFStringTransform((__bridge CFMutableStringRef)(pinyin), NULL, kCFStringTransformStripCombiningMarks, NO); | ||
return pinyin; | ||
} | ||
|
||
- (NSArray*)pinyinArray{ | ||
NSArray *array = [[self pinyin] componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; | ||
return array; | ||
} | ||
|
||
- (NSString*)pinyinWithoutBlank{ | ||
NSMutableString *string = [NSMutableString stringWithString:@""]; | ||
for (NSString *str in [self pinyinArray]) { | ||
[string appendString:str]; | ||
} | ||
return string; | ||
} | ||
|
||
- (NSArray*)pinyinInitialsArray{ | ||
NSMutableArray *array = [NSMutableArray array]; | ||
for (NSString *str in [self pinyinArray]) { | ||
if ([str length] > 0) { | ||
[array addObject:[str substringToIndex:1]]; | ||
} | ||
} | ||
return array; | ||
} | ||
|
||
- (NSString*)pinyinInitialsString{ | ||
NSMutableString *pinyin = [NSMutableString stringWithString:@""]; | ||
for (NSString *str in [self pinyinArray]) { | ||
if ([str length] > 0) { | ||
[pinyin appendString:[str substringToIndex:1]]; | ||
} | ||
} | ||
return pinyin; | ||
} | ||
|
||
@end |
24 changes: 24 additions & 0 deletions
24
Categories/Foundation/NSUserDefaults/NSUserDefaults+iCloudSync.h
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,24 @@ | ||
// | ||
// NSUserDefaults+iCloudSync.h | ||
// | ||
// Created by Riccardo Paolillo on 09/05/13. | ||
// Copyright (c) 2013. All rights reserved. | ||
// | ||
|
||
//https://github.com/RiccardoPaolillo/NSUserDefault-iCloud | ||
// A very simple iOS Category for synchronize NSUserDefaults with iCloud (NSUbiquitousKeyValueStore) | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
@interface NSUserDefaults (iCloudSync) | ||
|
||
-(void)setValue:(id)value forKey:(NSString *)key iCloudSync:(BOOL)sync; | ||
-(void)setObject:(id)value forKey:(NSString *)key iCloudSync:(BOOL)sync; | ||
|
||
-(id)valueForKey:(NSString *)key iCloudSync:(BOOL)sync; | ||
-(id)objectForKey:(NSString *)key iCloudSync:(BOOL)sync; | ||
|
||
-(BOOL)synchronizeAlsoiCloudSync:(BOOL)sync; | ||
|
||
@end |
Oops, something went wrong.