gpt4 book ai didi

xcode - Swift:2个连续的闭包/ block

转载 作者:搜寻专家 更新时间:2023-10-31 19:35:37 24 4
gpt4 key购买 nike

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

这是使用完成 block 和 progressBlock 处理文件保存的建议语法。

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:

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

Another attempt, another error

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

enter image description here

最佳答案

我用方法签名在 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")
})

关于xcode - Swift:2个连续的闭包/ block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24548837/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com