在Objective-C中,代码看起来很喜欢这个并且工作得很完美,
NSInteger random = arc4random_uniform(99) + 1 NSData *data = [NSData dataWithBytes:& random length: sizeof(random)]; int value = *(int*)([data bytes]);
怎么能在Swift中完成?
像这样:
var src: NSInteger = 2525 var out: NSInteger = 0 let data = NSData(bytes: &src,length: sizeof(NSInteger)) data.getBytes(&out,length: sizeof(NSInteger)) println(out) // ==> 2525