0

我发现我的 CouchModel (TSCAssetUploadDO) 保存了附件但不保存属性。

    TSCAssetUploadDO *assetDO = [[TSCAssetUploadDO alloc] initWithNewDocumentInDatabase: _localAssetUploadDatabase];
    NSData *data = UIImageJPEGRepresentation(contact.avatar, 1.0); // may need to resize.
    NSString *attachmentName = [docID stringByAppendingString:@".jpg"];
    [assetDO createAttachmentWithName:attachmentName type:@"image/jpeg" body:data];
    assetDO.relatedDocID = docID;
    assetDO.docType = @"contact";
    RESTOperation *op2 = [assetDO save];
    //[op2 wait]; originally thought that making it sync may work
    [op2 onCompletion:^{
        if (op2.error) NSLog(@"ERROR [TOUCHDB] %@", op2.error);
        else
        {
            NSLog(@"YES! it saved");
        }
        if (completionBlock)
        {
            completionBlock(op2.error, contact);
        }
        //[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationDataUpdated object:nil];
    }];

这导致了这样的文档(虽然保存了附件,但没有像 docType 和 relatedDocID 这样的属性)

{
 "_id": "D50ED630-34ED-4A02-A9C8-204E79A0648B",
 "_rev": "1-b0ce9eaa1fb2f86dc9ae619e27ffe1ea",
 "_attachments": {
   "QSPNGC665.jpg": {
       "content_type": "image/jpeg",
       "revpos": 1,
       "digest": "md5-u9V0rgoSRN5cUW2T3xh0hw==",
       "length": 117500,
       "stub": true
   }
 }
}

下面是我刚刚使用的 CouchModel。

@interface TSCAssetUploadDO: CouchModel
  @property(nonatomic,retain) NSString *relatedDocID;
  @property(nonatomic,retain) NSString *docType;//entity or contact
  @property bool *toProcess;
  @property (retain) NSDate* created_at;
@end

@implementation TSCAssetUploadDO

  - (NSDictionary*) propertiesToSave {
     // Initialize created_at the first time the document is saved:
     if (self.created_at == nil)
      self.created_at = [NSDate date];
     return [super propertiesToSave];
     }
 @end

有什么我做错了吗?

4

1 回答 1

1

解决了我的问题。需要添加@dynamic

@implementation TSCAssetUploadDO
   @dynamic relatedDocID, docType, toProcess, created_at;
   <... rest of the code >
@end
于 2013-09-27T03:15:34.157 回答