In Objective-C the code looked liked this and worked flawlessly,
NSInteger random = arc4random_uniform(99) + 1 NSData *data = [NSData dataWithBytes:& ra
My contribution with a swift 3.1 extension :
extension NSData{ var int : Int{ var out: Int = 0 self.getBytes(&out, length: MemoryLayout.size) return out } }
Just call .int to get your value, just like this :
let value = 50 let data = NSData(bytes: &value, length: 4) print(data.int)