Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2013 Kyle Robson (http://kylerobson.com)

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.
1 change: 1 addition & 0 deletions NSData+ZSAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#import "NSData+ZSAdditions.h"
#import <CommonCrypto/CommonDigest.h>
#import "ZSShared.h"

@implementation NSData (ZSAdditions)

Expand Down
1 change: 1 addition & 0 deletions NSString+ZSAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#import "NSString+ZSAdditions.h"
#import "NSData+ZSAdditions.h"
#import "ZSShared.h"

@implementation NSString(ZSAdditions)

Expand Down
1 change: 1 addition & 0 deletions UIImageView+ZSAssetManagerAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "UIImageView+ZSAssetManagerAdditions.h"
#import "ZSAssetManager.h"
#import <objc/runtime.h>
#import "ZSShared.h"

static char const * const assetManagerImageURLKey = "assetManagerImageURLKey";

Expand Down
1 change: 1 addition & 0 deletions ZDSStreamJSONParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// OTHER DEALINGS IN THE SOFTWARE.

#import "YAJLParser.h"
#import <CoreData/CoreData.h>

@interface ZDSStreamJSONParser : NSObject <YAJLParserDelegate>

Expand Down
1 change: 1 addition & 0 deletions ZDSStreamJSONParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// OTHER DEALINGS IN THE SOFTWARE.

#import "ZDSStreamJSONParser.h"
#import "ZSShared.h"

@implementation ZDSStreamJSONParser

Expand Down
4 changes: 2 additions & 2 deletions ZSAssetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
#import "ZSAssetManager.h"
#import "ZSURLConnectionDelegate.h"
#import "ZSReachability.h"

#import "NSString+ZSAdditions.h"
#import "ZSShared.h"

#define kCachePath @"imageCache"

Expand Down Expand Up @@ -98,7 +98,7 @@ - (id)init
self = [super init];

// TODO: Is there a way to avoid object:nil?
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kZSReachabilityChangedNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(flushMemoryCaches:) name:UIApplicationDidReceiveMemoryWarningNotification object:[UIApplication sharedApplication]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enteringBackground:) name:UIApplicationDidEnterBackgroundNotification object:[UIApplication sharedApplication]];
Expand Down
8 changes: 5 additions & 3 deletions ZSContextWatcher.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

@interface ZSContextWatcher : NSObject
#import <CoreData/CoreData.h>

@interface ZSContextWatcher : NSObject
{
NSPersistentStoreCoordinator *persistentStoreCoordinator;
NSPredicate *masterPredicate;
NSString *reference;

Expand All @@ -41,7 +42,8 @@
@property (nonatomic, retain) NSPredicate *masterPredicate;
@property (nonatomic, retain) NSString *reference;

- (id)initWithManagedObjectContext:(NSManagedObjectContext*)context;
- (id)initWithManagedObjectContextToWatch:(NSManagedObjectContext*)contextToWatch;
- (id)initWithPersistentStoreCoordinatorToWatch:(NSPersistentStoreCoordinator*)persistentStoreCoordinatorToWatch;

- (void)addEntityToWatch:(NSEntityDescription*)description withPredicate:(NSPredicate*)predicate;

Expand Down
51 changes: 42 additions & 9 deletions ZSContextWatcher.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,53 @@
// OTHER DEALINGS IN THE SOFTWARE.

#import "ZSContextWatcher.h"
#import "ZSShared.h"

@interface ZSContextWatcher ()

@property (nonatomic, strong) NSManagedObjectContext *contextToWatch;
@property (nonatomic, strong) NSPersistentStoreCoordinator *persistentStoreCoordinatorToWatch;

@end

@implementation ZSContextWatcher

- (id)initWithManagedObjectContext:(NSManagedObjectContext*)context;
- (id)initWithManagedObjectContextToWatch:(NSManagedObjectContext*)contextToWatch
{
ZAssert(context, @"Context is nil!");
ZAssert(contextToWatch, @"Context is nil!");
[super init];

self.contextToWatch = contextToWatch;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contextUpdated:) name:NSManagedObjectContextDidSaveNotification object:nil];

persistentStoreCoordinator = [context persistentStoreCoordinator];

return self;
}

- (id)initWithPersistentStoreCoordinatorToWatch:(NSPersistentStoreCoordinator*)persistentStoreCoordinatorToWatch
{
ZAssert(persistentStoreCoordinatorToWatch, @"Persistent Store Coordinator is nil!");
[super init];

self.persistentStoreCoordinatorToWatch = persistentStoreCoordinatorToWatch;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contextUpdated:) name:NSManagedObjectContextDidSaveNotification object:nil];

return self;
}

- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
delegate = nil;
[masterPredicate release], masterPredicate = nil;
[masterPredicate release];
masterPredicate = nil;
[reference release];
reference = nil;
[_contextToWatch release];
_contextToWatch = nil;
[_persistentStoreCoordinatorToWatch release];
_persistentStoreCoordinatorToWatch = nil;
[super dealloc];
}

Expand All @@ -68,8 +95,15 @@ - (void)contextUpdated:(NSNotification*)notification
{
NSManagedObjectContext *incomingContext = [notification object];
NSPersistentStoreCoordinator *incomingCoordinator = [incomingContext persistentStoreCoordinator];
if (incomingCoordinator != [self persistentStoreCoordinator]) {
return;
if (self.contextToWatch != nil) {
if (incomingContext != self.contextToWatch) {
return;
}
}
else if (self.persistentStoreCoordinatorToWatch != nil) {
if (incomingCoordinator != self.persistentStoreCoordinatorToWatch) {
return;
}
}
if ([self reference]) {
DLog(@"%@ entered", [self reference]);
Expand Down Expand Up @@ -101,7 +135,7 @@ - (void)contextUpdated:(NSNotification*)notification
if ([self reference]) {
DLog(@"%@++++++++++firing action", [self reference]);
}
[[self delegate] performSelectorOnMainThread:[self action] withObject:self waitUntilDone:YES];
[[self delegate] performSelectorOnMainThread:[self action] withObject:results waitUntilDone:YES];
} else {
if ([self reference]) {
DLog(@"%@----------delegate doesn't respond", [self reference]);
Expand All @@ -113,7 +147,6 @@ - (void)contextUpdated:(NSNotification*)notification
[updated release], updated = nil;
}

@synthesize persistentStoreCoordinator;
@synthesize delegate;
@synthesize action;
@synthesize masterPredicate;
Expand Down
2 changes: 1 addition & 1 deletion ZSReachability.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef enum {
ReachableViaWiFi,
ReachableViaWWAN
} NetworkStatus;
#define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification"
#define kZSReachabilityChangedNotification @"kZSNetworkReachabilityChangedNotification"

@interface ZSReachability: NSObject
{
Expand Down
5 changes: 2 additions & 3 deletions ZSReachability.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
#import <arpa/inet.h>
#import <ifaddrs.h>
#import <netdb.h>

#import <CoreFoundation/CoreFoundation.h>

#import "ZSReachability.h"
#import "ZSShared.h"

#define kShouldPrintReachabilityFlags 1

Expand Down Expand Up @@ -92,7 +91,7 @@ static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReach

ZSReachability* noteObject = (ZSReachability*) info;
// Post a notification to notify the client that the network reachability changed.
[[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject];
[[NSNotificationCenter defaultCenter] postNotificationName: kZSReachabilityChangedNotification object: noteObject];

[myPool release];
}
Expand Down
32 changes: 32 additions & 0 deletions ZSShared.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// ZSShared.h
// Channel4000
//
// Created by Kyle Robson on 12/18/13.
// Copyright (c) 2013 Internet Broadcasting. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

#ifdef DEBUG
#define MCRelease(x) [x release]
#define DLog(...) NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__])
#define DCLog(...) NSLog(@"%@", [NSString stringWithFormat:__VA_ARGS__])
#define ALog(...) {NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__]);[[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__];}
#else
#define MCRelease(x) [x release], x = nil
#define DLog(...) do { } while (0)
#define DCLog(...) do { } while (0)
#ifndef NS_BLOCK_ASSERTIONS
#define NS_BLOCK_ASSERTIONS
#endif
#define ALog(...) NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__])
#endif

#define ZAssert(condition, ...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0)

#define ISRETINADISPLAY (([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) ? [[UIScreen mainScreen] scale] > 1.0 : NO)

#define degreesToRadians(x) (M_PI * x / 180.0)
2 changes: 1 addition & 1 deletion ZSURLConnectionDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
*/

#import "ZSURLConnectionDelegate.h"

#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "ZSShared.h"

static NSInteger activityCount;

Expand Down