Converting NSData to Integer in Swift

后端 未结 7 2083
予麋鹿
予麋鹿 2021-01-05 02:29

In Objective-C the code looked liked this and worked flawlessly,

NSInteger random = arc4random_uniform(99) + 1 
NSData *data = [NSData dataWithBytes:& ra         


        
相关标签:
7条回答
  • 2021-01-05 03:31

    Like this:

    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
    
    0 讨论(0)
提交回复
热议问题