根据这里的文档:https://www.parse.com/docs/ios_guide#files-progress/iOS

这是使用完成块和进度块处理文件保存的建议语法。

let str = "Working at Parse is great!"
let data = str.dataUsingEncoding(NSUTF8StringEncoding)
let file = PFFile(name:"resume.txt", data:data)
file.saveInBackgroundWithBlock {
  (succeeded: Bool!, error: NSError!) -> Void in
  // Handle success or failure here ...
}, progressBlock: {
  (percentDone: Int) -> Void in
  // Update your progress spinner here. percentDone will be between 0 and 100.
}

但是,XCode 6.2 会引发此错误:
一行中的连续语句必须用“;”分隔

在这一行:
}, progressBlock: {

有人知道如何在这种情况下正确使用 progressBlock 吗?

编辑1:
这是 Obj C 中的示例:
NSData *data = [@"Working at Parse is great!" dataUsingEncoding:NSUTF8StringEncoding];
PFFile *file = [PFFile fileWithName:@"resume.txt" data:data];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
  // Handle success or failure here ...
} progressBlock:^(int percentDone) {
  // Update your progress spinner here. percentDone will be between 0 and 100.
}];

编辑2:

另一种尝试,不同的错误:

编辑3:
原始代码,但根据评论建议使用 CInt

最佳答案

我在 Objective C 中定义了一个带有方法签名的类:

- (void)saveInBackgroundWithBlock:(void(^)(BOOL succeeded, NSError *error))block progressBlock:(void(^)(int percentDone))progressBlock;

我可以在 Swift 中这样称呼它:
let file = Test()
file.saveInBackgroundWithBlock({(success: Bool, error: NSError!) -> Void in
        NSLog("1")
    }, progressBlock: { (percentage: CInt) -> Void in
        NSLog("2")
    })

10-07 19:55
查看更多