-
-
Save nuclearace/5d3d1737002f12be6109 to your computer and use it in GitHub Desktop.
Breaks Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@class MyTester; | |
@interface Breaker: NSObject | |
@property (nonatomic) MyTester* tester; | |
- (void)breakSwift; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import "blockerror-Swift.h" | |
#import "Breaker.h" | |
@implementation Breaker: NSObject | |
-(id)init { | |
if (!(self = [super init])) { | |
return nil; | |
} | |
MyTester* tester = [[MyTester alloc] init]; | |
self.tester = tester; | |
[self breakSwift]; | |
return self; | |
} | |
-(void)breakSwift { | |
__block int i; | |
[[self tester] addAck:0](^(NSArray* data) { | |
NSLog(@"breaing swift"); | |
i = 1 + 1; | |
NSLog(@"%i", i); | |
}); | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "Breaker.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public typealias Callback = (NSArray) -> Void | |
struct AckMap { | |
private var acks = [Int: Callback]() | |
mutating func addAck(num:Int, callback:Callback) { | |
self.acks[num] = callback | |
} | |
mutating func executeAck(ack:Int, items:[AnyObject]) { | |
self.acks[ack]?(items) | |
self.acks.removeValueForKey(ack) | |
} | |
} | |
public class MyTester: NSObject { | |
var acks = AckMap() | |
public func addAck(num:Int) -> (Callback) -> Void { | |
return {[weak self] callback in | |
callback([0]) | |
self?.acks.addAck(num, callback: callback) | |
return | |
} | |
} | |
public func breakObjc(num:Int) { | |
self.acks.executeAck(num, items: ["break"]) | |
} | |
} | |
let breaker = Breaker() | |
breaker.tester.breakObjc(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change
Callback
toand the crash goes away.