What kind of data structure should I use that would allow me to store tabular data (and append new data to it), as well as operate over it (calc aggregations, etc).
Specifically I'm looking for something similar to pandas
(for python). Right now I don't need to draw the data table but, only to store data.
For example, imagine I want to append values to a table every 5 seconds, so that, every hour I will aggregate the information into a new data structure.
The swift Datastore is our central database. Essentially it contains all ICAO data for airlines and aircraft types, liveries, aircraft&model distributors, model data, aircraft mapping information, admin-functions to work with user change requests and more.
You can use files to store larger amounts of data. Document-based apps, such as text editors, spreadsheets, and drawing apps, usually save their data in files. Apple provides the Codable protocol to simplify reading and writing data to files. An Internet search for Swift Codable tutorial yields many results, most of which cover JSON.
You can use NSUserDefaults. Here is the information you need codingexplorer.com/nsuserdefaults-a-swift-introduction The simplest solution for storing a few strings or common types is UserDefaults. The UserDefaults class provides convenience methods for accessing common types such as floats, doubles, integers, Boolean values, and URLs.
You can use multiple methods to save data in your app. Many iOS and Mac apps use both UserDefaults and Core Data to save data. Use all the methods for saving data that make sense for your app. Apple provides a UserDefaults class that provides a programming interface to your app’s defaults database.
Maybe this could help you?
struct Table<T>{
typealias Columns = [T]
typealias Rows = [Columns]
private var data: Rows = []
mutating func appendRow(row: Columns){
data.append(row)
}
func getRow(index: Int) -> Columns?{
return data[safe: index]
}
}
var intTable = Table<Int>()
intTable.appendRow(row: [1,2,3,4])
intTable.appendRow(row: [1,2,3])
var anyTable = Table<Any>()
anyTable.appendRow(row: ["Hello World", 12])
Apple has made a framework for this called TabularData.
It allows you to import & export data from JSON & CSV files as well as programatically storing, sorting and summarising tabular data with simple statistics like element count, maximum, mininum, mean, and standard deviation.
Note that it only works on iOS 15.0+, macOS 12.0+, tvOS 15.0+, or watchOS 8.0+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With