Questions tagged [swift-data]

12 questions
101
votes
3 answers

round trip Swift number types to/from Data

With Swift 3 leaning towards Data instead of [UInt8], I'm trying to ferret out what the most efficient/idiomatic way to encode/decode swifts various number types (UInt8, Double, Float, Int64, etc) as Data objects. There's this answer for using…
Travis Griggs
  • 18,930
  • 17
  • 76
  • 137
5
votes
4 answers

Difference between Int and Uint8 swift

What are the differences between the data types Int & UInt8 in swift. Looks like UInt8 is used for binary data, i need to convert UInt8 to Int is this possible.
nuteron
  • 471
  • 1
  • 8
  • 25
4
votes
3 answers

native zlib inflate/deflate for swift3 on iOS

I'd like to be able to inflate/deflate Swift3 Data structs. I found GzipSwift, but it's not clear how I make that available to my iOS app. The naive things I've tried include: Copying the Data+Gzip.swift file into my own project. This then…
Travis Griggs
  • 18,930
  • 17
  • 76
  • 137
3
votes
1 answer

Split Data in chunks and upload to server

I have a file that needed to be uploaded to a server and I have been told to separate the file into multiple chunks before uploading. So here is the question: 1) I have converted the file into "Data" type (bytes). How do I split it into chunks of…
da32
  • 623
  • 1
  • 8
  • 17
2
votes
1 answer

Storing data into class

so I am currently working on my first bigger project and I was wondering wether there is some way of putting data into one class and then just rewriting them or making an instance for the class. I have got a data that are being downloaded in the…
Pepa
  • 31
  • 6
2
votes
1 answer

Swift: How to save a Decodable.Protocol object to a variable?

In my application, several controllers have a very similar code structure, the differences are minimal, so for optimization I decided to create a basis for these controllers, and inherit each specific controller from the basis. I have a function for…
2
votes
2 answers

Data <-> MutableRandomAccessSlice

I am really struggling with the fact that someData[start...stop] returns a MutableRandomAccessSlice. My someData was a let to begin with, so why would I want a Mutable thing? Why don't I get just a RandomAccessSlice. What's really frustrating…
Travis Griggs
  • 18,930
  • 17
  • 76
  • 137
2
votes
2 answers

Idiomatic method of parsing swift(3) data streams

I'm trying to do some simple BSON parsing of Swift3 Data objects. I feel like I'm fighting the system. Let's start with some input and a scheme: let input = Data(bytes: [2, 0x20, 0x21, 3, 0x30, 0x31, 0x32, 1, 0x10, 4, 0x40, 0x41, 0x42, 0x43]) This…
Travis Griggs
  • 18,930
  • 17
  • 76
  • 137
0
votes
2 answers

How can I convert a JSON as Data Type in Swift?

I want to send data to my websocket server in swift but the websocket server write function only accepts strings or the data type. Since I did not find any JSON.stringify option for swift I used swiftyJson to create my own type of JSON, but now I…
Lucas Goldner
  • 347
  • 2
  • 11
0
votes
1 answer

What is the correct data type for binding variable of an array's element

I have a struct of that is a part of the data set as below: var exercise: [Exercise] struct Exercise: Codable { var id = UUID() var exercise, set: Int } In my code (View1) I loop through the exercise array and reach each element…
Danny
  • 99
  • 5
0
votes
2 answers

Issue Using Swift's withUnsafeMutableBytes Wrapper

I'm trying to write an extension to Data that allows me to extract it in various casts. I'm running into a strange problem that I can't quite figure out. Before I get into generics, I'm trying out fixed data types, and I created this method: func…
Chris Marshall
  • 4,044
  • 6
  • 39
  • 56
0
votes
0 answers

Converting Data to SKSpriteNode

I am having an issue working with Data and SKSpriteNodes, specifically, the conversion back from Data to SKSpriteNode. I have tried both methods of converting from data to something found here, specifically this line: let data:SKSpriteNode =…
Rocket6488
  • 128
  • 1
  • 9