mirror of
https://github.com/mssun/passforios.git
synced 2026-02-27 18:24:03 +01:00
This process is necessary because of an issue (https://github.com/golang/go/issues/33745) in gomobile. Passing bare Data objects to Go functions leads to nondeterministic behavior.
20 lines
740 B
Swift
20 lines
740 B
Swift
//
|
|
// Data+Mutable.swift
|
|
// passKit
|
|
//
|
|
// Created by Danny Moesch on 08.09.19.
|
|
// Copyright © 2019 Bob Sun. All rights reserved.
|
|
//
|
|
|
|
extension Data {
|
|
/// This computed value is only needed because of [this](https://github.com/golang/go/issues/33745) issue in the
|
|
/// golang/go repository. It is a workaround until the problem is solved upstream.
|
|
///
|
|
/// The data object is converted into an array of bytes and than returned wrapped in an `NSMutableData` object. In
|
|
/// thas way Gomobile takes it as it is without copying. The Swift side remains responsible for garbage collection.
|
|
var mutable: NSMutableData {
|
|
var array = [UInt8](self)
|
|
return NSMutableData(bytes: &array, length: count)
|
|
}
|
|
}
|