#import "DataBase.h"
#include "AppDelegate.h"
#import "DataEntity.h"
@interface DataBase ()
@property(nonatomic,strong)AppDelegate *myDelegate;
@property(nonatomic,strong)NSMutableArray *allArr;
static DataBase *sharedDataBase =nil;
@implementation DataBase
+(instancetype)sharedDataBase
{
if (sharedDataBase==nil) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedDataBase =[[DataBase alloc]init];
});
}
return sharedDataBase;
}
+(instancetype)allocWithZone:(struct _NSZone *)zone
{
if (sharedDataBase==nil) {
sharedDataBase =[super allocWithZone:zone];
}
return sharedDataBase;
}
-(void)insertData:(NSString *)name sing:(NSString *)sing
{
self.allArr = [NSMutableArray array];
self.myDelegate = [UIApplication sharedApplication].delegate;
DataEntity *entity = [[DataEntity alloc]initWithEntity:[NSEntityDescription entityForName:@"DataEntity" inManagedObjectContext:self.myDelegate.managedObjectContext] insertIntoManagedObjectContext:self.myDelegate.managedObjectContext];
entity.name = name;
entity.sing = sing;
}
-(NSArray *)showData
{
NSArray *arr = [self.myDelegate.managedObjectContext executeFetchRequest:[NSFetchRequest fetchRequestWithEntityName:@"DataEntity"] error:nil];
NSLog(@"arr:%@",arr);
return arr;
}