我有一个允许用户保存收藏夹的应用程序.我使用Core Data将收藏夹存储为托管对象.我已经编写了一些代码来防止存储重复项的可能性,但我想知道是否有更好的方法来执行此操作.每个喜欢的对象都有一个唯一的ID字段.在下面的代码中,我只是循环并检查ID字段,如果该值已经存在,则将标志值设置为true,并打破循环.
-(BOOL)addFavorite{
BOOL entityExists = NO;
if(context){
// does this favorite already exist?
NSArray *allFaves = [AppDataAccess getAllFavorites];
for(Favorite *f in allFaves){
if([f.stationIdentifier isEqualToString:stID]){
entityExists = YES;
break;
}
}
if(!entityExists){
NSError *err = nil;
Favorite *fave = [Favorite insertInManagedObjectContext:context];
fave.stationRealName = riverGauge.name;
fave.stationIdentifier = stID;
fave.stationState = @"WV";
if(![context save:&err]){
NSLog(@"ERROR: Could not save context--%@", err);
}
return YES;
}
return NO;
}
Run Code Online (Sandbox Code Playgroud)
我想知道Core Data是否能够检查添加的对象是否重复.是否有可以处理重复检查的谓词?谢谢!
我有兴趣在我的应用程序中实现左侧菜单我已经使用了NVSlideMenuController.它工作正常.
但我想修改它.我想用contentViewController滑动状态栏,不想在MenuViewController上显示状态栏.
目前它看起来像下面的图像

我想和下面的图像一样

提前致谢
我在我的应用项目中实施了Google Drive SDK.并尝试在Google云端硬盘中上传图片但我收到错误.
我从这里做代码
当我运行此代码时,我得到了以下错误
Error Domain=com.google.GTLJSONRPCErrorDomain Code=400 "The operation couldn’t be completed. (Invalid Value)" UserInfo=0x276940 {NSLocalizedFailureReason=(Invalid Value), GTLStructuredError=GTLErrorObject 0x2fade0: {message:"Invalid Value" code:400 data:[1]}, error=Invalid Value}
Run Code Online (Sandbox Code Playgroud)
请给我这个建议.提前致谢