同步核心数据中的数据

时间:2017-06-15 09:04:57

标签: swift core-data

我有一个名为students_server和students_db的数组。 students_server从服务器获取学生数组,students_db从核心数据中获取学生数组。 我想在核心数据中同步students_server

1)删除student_server中不存在的学生

2)更新核心数据和students_server

中的学生

3)插入核心数据中不存在的学生,但在students_server

中插入

采用以下解决方案

#import <CommonCrypto/CommonHMAC.h>

+ (NSString *)hmacSHA256EncryptString{


    NSString * parameterSecret = @"input secret key";
    NSString *plainString = @"input encrypt content string";
    const char *secretKey  = [parameterSecret cStringUsingEncoding:NSUTF8StringEncoding];
    const char *plainData = [plainString cStringUsingEncoding:NSUTF8StringEncoding];
    unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
    CCHmac(kCCHmacAlgSHA256, secretKey, strlen(secretKey), plainData, strlen(plainData), cHMAC);
    NSData *HMACData = [NSData dataWithBytes:cHMAC length:sizeof(cHMAC)];
    const unsigned char *bufferChar = (const unsigned char *)[HMACData bytes];
    NSMutableString *hmacString = [NSMutableString stringWithCapacity:HMACData.length * 2];
    for (int i = 0; i < HMACData.length; ++i){
        [hmacString appendFormat:@"%02x", bufferChar[i]];
    }
    return hmacString;
    
}

就像在Android中一样,我们有这个

class Students: NSManagedObject { @NSManaged var id: String @NSManaged var image: String @NSManaged var name: String }

0 个答案:

没有答案