How to convert an Int into NSData in Swift?

前端 未结 7 1921
陌清茗
陌清茗 2021-02-03 22:37

In Objective-C I use the following code to

  1. Convert an Int variable into NSData, a packet of bytes.

    int myScore = 0;
    NS         
    
    
            
7条回答
  •  暖寄归人
    2021-02-03 23:04

    You can convert in this way:

    var myScore: NSInteger = 0
    let data = NSData(bytes: &myScore, length: sizeof(NSInteger))
    

提交回复
热议问题