Skip to content

Commit 0a448ea

Browse files
committed
SE-0138: Minor update. Array.withUnsafeBytes is nonmutating.
The "mutating" keyword should not have been on this API. The example code in SE-0138 uses it as a nonmutating API. (The mutating keyword was a temporary workaround that should never have been carried over to the swift-3.0-branch). <rdar://28614519> [swift-3.0-branch] Remove "mutating" keyword from Array.withUnsafeBytes
1 parent 9a5a26b commit 0a448ea

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

stdlib/public/core/Arrays.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,7 @@ extension ${Self} {
21702170
/// - Returns: The return value of the `body` closure parameter, if any.
21712171
///
21722172
/// - SeeAlso: `withUnsafeBytes`, `UnsafeRawBufferPointer`
2173-
public mutating func withUnsafeBytes<R>(
2173+
public func withUnsafeBytes<R>(
21742174
_ body: (UnsafeRawBufferPointer) throws -> R
21752175
) rethrows -> R {
21762176
return try self.withUnsafeBufferPointer {

test/stdlib/UnsafeRawBufferPointer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ UnsafeRawBufferPointerTestSuite.test("nonmutating_subscript_setter") {
5353
// View an array's elements as bytes.
5454
// Use copyBytes to overwrite the array element's bytes.
5555
UnsafeRawBufferPointerTestSuite.test("initFromArray") {
56-
var array1: [Int32] = [0, 1, 2, 3]
56+
let array1: [Int32] = [0, 1, 2, 3]
5757
var array2 = [Int32](repeating: 0, count: 4)
5858
// Immutable view of array1's bytes.
5959
array1.withUnsafeBytes { bytes1 in
@@ -77,7 +77,7 @@ UnsafeRawBufferPointerTestSuite.test("initFromArray") {
7777

7878
// Directly test the byte Sequence produced by withUnsafeBytes.
7979
UnsafeRawBufferPointerTestSuite.test("withUnsafeBytes.Sequence") {
80-
var array1: [Int32] = [0, 1, 2, 3]
80+
let array1: [Int32] = [0, 1, 2, 3]
8181
array1.withUnsafeBytes { bytes1 in
8282
// Initialize an array from a sequence of bytes.
8383
let byteArray = [UInt8](bytes1)

0 commit comments

Comments
 (0)