Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (55 sloc) 3.28 KB
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#pragma mark - Networking
#define HOST @"wss://acani-chat.jit.su/"
//#define HOST @"ws://localhost:5000/"
static NSUInteger _networkActivityIndicatorCount = 0;
UIKIT_STATIC_INLINE void AppSetNetworkActivityIndicatorVisible(BOOL visible) {
if (visible) {
++_networkActivityIndicatorCount;
} else {
assert(_networkActivityIndicatorCount > 0);
--_networkActivityIndicatorCount;
}
[UIApplication sharedApplication].networkActivityIndicatorVisible = (_networkActivityIndicatorCount > 0);
}
#pragma mark - Core Data
#define MOCSave(managedObjectContext) { \
NSError __autoreleasing *error = nil; \
NSAssert([managedObjectContext save:&error], @"-[NSManagedObjectContext save] error:\n\n%@", error); }
#define MOCCount(managedObjectContext, fetchRequest) \
NSManagedObjectContextCount(self, _cmd, managedObjectContext, fetchRequest)
#define MOCCountAll(managedObjectContext, entityName) \
MOCCount(_managedObjectContext, [NSFetchRequest fetchRequestWithEntityName:entityName])
#define MOCFetch(managedObjectContext, fetchRequest) \
NSManagedObjectContextFetch(self, _cmd, managedObjectContext, fetchRequest)
#define MOCFetchAll(managedObjectContext, entityName) \
MOCFetch(_managedObjectContext, [NSFetchRequest fetchRequestWithEntityName:entityName])
#define MOCDelete(managedObjectContext, fetchRequest, cascadeRelationships) \
NSManagedObjectContextDelete(self, _cmd, managedObjectContext, fetchRequest, cascadeRelationships)
#define MOCDeleteAll(managedObjectContext, entityName, cascadeRelationships) \
MOCDelete(managedObjectContext, [NSFetchRequest fetchRequestWithEntityName:entityName], cascadeRelationships)
#define FRCPerformFetch(fetchedResultsController) { \
NSError __autoreleasing *error = nil; \
NSAssert([fetchedResultsController performFetch:&error], @"-[NSFetchedResultsController performFetch:] error:\n\n%@", error); }
NS_INLINE NSUInteger NSManagedObjectContextCount(id self, SEL _cmd, NSManagedObjectContext *managedObjectContext, NSFetchRequest *fetchRequest) {
NSError __autoreleasing *error = nil;
NSUInteger objectsCount = [managedObjectContext countForFetchRequest:fetchRequest error:&error];
NSAssert(objectsCount != NSNotFound, @"-[NSManagedObjectContext countForFetchRequest:error:] error:\n\n%@", error);
return objectsCount;
}
NS_INLINE NSArray *NSManagedObjectContextFetch(id self, SEL _cmd, NSManagedObjectContext *managedObjectContext, NSFetchRequest *fetchRequest) {
NSError __autoreleasing *error = nil;
NSArray *fetchedObjects = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
NSAssert(fetchedObjects, @"-[NSManagedObjectContext executeFetchRequest:error:] error:\n\n%@", error);
return fetchedObjects;
}
NS_INLINE void NSManagedObjectContextDelete(id self, SEL _cmd, NSManagedObjectContext *managedObjectContext, NSFetchRequest *fetchRequest, NSArray *cascadeRelationships) {
fetchRequest.includesPropertyValues = NO;
fetchRequest.includesPendingChanges = NO;
fetchRequest.relationshipKeyPathsForPrefetching = cascadeRelationships;
NSArray *fetchedObjects = MOCFetch(managedObjectContext, fetchRequest);
for (NSManagedObject *fetchedObject in fetchedObjects) {
[managedObjectContext deleteObject:fetchedObject];
}
}
Jump to Line
Something went wrong with that request. Please try again.