简体   繁体   English

用Swift编写完成块

[英]Writing completion block with Swift

I'm using Estimote's iOS SDK and I'm trying to write the following Objective-C code in Swift: 我正在使用Estimote的iOS SDK,并且尝试在Swift中编写以下Objective-C代码:

 [self.beaconConnection writeMajor:newMajor completion:^(unsigned short major, NSError *error)
        {
            if (error)
            {
                NSLog(@"Error major write: %@", error.localizedDescription);
            }

            self.majorTextFiled.text = [NSString stringWithFormat:@"%i", major];
        }];

I'm struggling with getting the completion block to work. 我正在努力使完成模块正常工作。

Here's what I have so far: 这是我到目前为止的内容:

beaconConnection.writeMajor(major, completion: { value, error in

            }
        )

I accidentally had major as Int and it's supposed to be UInt16 for that method. 我无意中获得了Int的专业学位,该方法应该是UInt16。 Here's the updated code: 这是更新的代码:

beaconConnection.writeMajor(UInt16(major), completion: { value, error in

            }
        )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM