hi
how can i modify the data in nsdata by bytes
for modify and reverse every bit in nsdata
hi
how can i modify the data in nsdata by bytes
for modify and reverse every bit in nsdata
You cannot modify the data in a NSData object — it's immutable. Instead, you must use a NSMutableData object, then you can modify the bytes using the pointer returned by the "mutableBytes" property.
That's for Swift 2 and earlier (Xcode 7.3.1 and earlier). For Swift 3 (Xcode 8 beta), you can use the new Data type, and the "withUnsafeMutableBytes ()" method.
For Swift 3, I rarely find the need to use 'withUnsafeMutableBytes'. Here's an example of what you can do:
var theData = ...
for theIndex in 0 ..< theData.count {
theData[theIndex] ^= 0xFF
}