在我的项目中,我有Objective-C和Swift代码.我有一些对象具有包含块的属性来清理一些UITableView配置.使用它在Objective-C中工作,但在使用Swift时崩溃.
我已经将问题减少到尽可能小,同时仍然可以重现.
// in Objective-C
@interface MyClass : NSObject
@property (copy, nonatomic) NSString* (^block)();
- (NSString *)callTheBlock;
@end
@implementation MyClass
- (NSString *)callTheBlock {
if (self.block) {
return self.block();
} else {
return @"There is no spoon";
}
}
@end
// In Swift
// I actually have this in my AppDelegate to run when the app starts, but that shouldn't matter
class AppDelegate: UIResponder, UIApplicationDelegate {
var myClass: MyClass?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
self.myClass = …Run Code Online (Sandbox Code Playgroud)