我有一个名为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 }