Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store tabular data on Swift

Tags:

ios

swift

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.

like image 792
Carlos Vega Avatar asked May 02 '19 11:05

Carlos Vega


People also ask

What is the Swift datastore?

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.

How can I store large amounts of data in Swift?

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.

What is the best way to store a string in Swift?

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.

How do I save data in an iOS app?

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.


2 Answers

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])
like image 92
TmKVU Avatar answered Oct 28 '22 12:10

TmKVU


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+

like image 1
Damiaan Dufaux Avatar answered Oct 28 '22 11:10

Damiaan Dufaux