0
我有我的UserFavourite類,看起來像這樣:Parse.com。自定義子類屬性不會保存。 iOS的
UserFavourite.h
#import <Foundation/Foundation.h>
#import <Parse/Parse.h>
#import "Product.h"
@interface UserFavourite : PFObject <PFSubclassing>
@property (nonatomic, copy) Product* product;
@property (nonatomic, copy) PFUser* user;
+(NSString *)parseClassName;
-(id)initWithProducts:(Product*)product
user:(PFUser *)user;
@end
UserFavourite.m
#import "UserFavourite.h"
#import <Parse/PFObject+Subclass.h>
@implementation UserFavourite
@dynamic product, user;
+(NSString *)parseClassName {
return @"UserFavourite";
}
-(id)initWithProducts:(Product*)product
user:(PFUser *)user{
self = [super init];
if (self) {
self.product = product;
self.user = user;
}
return self;
}
@end
這是我做的插入代碼:
//Getting product from Parse
PFQuery *query = [PFQuery queryWithClassName:@"Product"];
UserFavourite *uf = [[UserFavourite alloc] init];
[query getObjectInBackgroundWithId:@"NhKrnlzeeN" block:^(PFObject *product1, NSError *error) {
[uf setUser:[PFUser currentUser]];
Product* pr = [[Product alloc] init];
pr.name = [product1 objectForKey:@"name"];
pr.category = [product1 objectForKey:@"category"];
pr.price = [product1 objectForKey:@"price"];
pr.ingridients = [product1 objectForKey:@"ingridients"];
pr.protein = [product1 objectForKey:@"protein"];
pr.fats = [[product1 objectForKey:@"fats"] integerValue];
pr.carbo = [[product1 objectForKey:@"carbo"] integerValue];
pr.calories = [[product1 objectForKey:@"calories"] integerValue];
pr.likes = [[product1 objectForKey:@"likes"] integerValue];
pr.quantity = [[product1 objectForKey:@"quantity"] integerValue];
pr.status = [[product1 objectForKey:@"status"] integerValue];
pr.objectId = product1.objectId;
[uf setProduct:pr];
NSLog(@"uf %@", uf);
}];
[uf saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
// The object has been saved.
} else {
NSLog(@"Error: %@", error.description);
}
}];
我要救這個解析服務器,但這些屬性是沒有保存到表格中,如圖所示: 我也在AppDelegate中初始化了這個子類。 我在這裏做錯了什麼? 謝謝。
我在AppDelegate中這樣做,我注意到當我調試時,執行不會超過getObjectInBackgroundWithId的第一行。它甚至不做任何修改。我真的不明白這種情況。 – Sermilion
另外,您需要確保用戶已經登錄並且[PFUser currentUser}不爲零。 – picciano