Best way to import data in Swift?

Mohammed B

I'm looking for the best way (or easiest) to import data into my iOS app using Swift. I've got a file containing recipes and I have to read in the recipe names and instructions. Example:

Fudge brownies

  1. Mix ingredients in processors until consistent.
  2. Prepare baking sheet with coconut oil and set over at 425. ....

So I have to import several dozen recipes, my questions are

Would it be best to read in a text file?

If so how is this done in Swift?

Also how do I avoid issues with reading the title and recipe into separate variables?

trevorj

You can read in a text file quite easily doing something like this:

let path = NSBundle.mainBundle().pathForResource("fileName", ofType: "txt")
var dataString = String(contentsOfFile: path!, encoding: NSUTF8StringEncoding, error: nil)

Note you'll have to import Foundation.

You could then create a method to parse the dataString, something like

func parseDataString(string: String)

which you could send the dataString to.

You could put markers (e.g. special characters like (*) ) in the text file that would allow this method to figure out where the titles end and the directions start. There are a number of ways it could be done.

You could then persist your data using CoreData.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Best way to import data in Swift?

From Dev

Best way to import bulk data into ArangoDB

From Dev

best way to import data from a php into tableview

From Dev

Best way to import delimited and paginated data with Python

From Dev

SpriteKit Swift best way to save level data

From Dev

Best way to export DB data in PHP, modify it, and import it

From Dev

Best way to import data into Cassandra Cluster in c#

From Dev

Best way to export DB data in PHP, modify it, and import it

From Dev

Best way to import data into Cassandra Cluster in c#

From Dev

Best way to import MongoDB data in Azure Machine Learning

From Dev

What is the best way to pass data in a hierarchical structure? Swift

From Dev

Best way to sort data

From Dev

Best way to encode data

From Dev

Best way to transform data

From Dev

Best way to persist data?

From Dev

Best way to erase on a picture in Swift?

From Dev

Best way to implement pointer in Swift

From Dev

Swift - Best way to write an if else

From Dev

What is the best way to implement shorting(Multiple time on single data) and filter with core data with Swift 3?

From Dev

best way to import external javascript with typescript

From Dev

Best way to import a Python list into an HTML table?

From Dev

What is the best way to import an element dependency?

From Dev

Best way to handle disposable data

From Dev

best way to store data in session

From Dev

Best way to build this data structure

From Dev

Best way to model data in Firebase

From Dev

Best way of representing binary data

From Dev

Best way to access data in react

From Dev

Best way to save data in android