file management in swift 3

1

I'm starting with this language and in this particular exercise I want to use the Utilities.swift file in the FMDB folder in a CategoriasViewController.swift file in the Controllers folder.

The folders are created in a "physical" way, that is, they have been created inside the main project folder, thanks

I think we would solve it with an import or something like that but I can not find the correct syntax

    
asked by Kevtho 29.03.2017 в 05:43
source

2 answers

1

The first step you must do is to have the files referenced in your project. When it appears in red, it means that you have found the files but they are not referenced in the project (probably because you have added them without references or because you have added them from the Finder).

To do this: Right click on the folder where you want to add the file - > Add Files to "MyProject"

Once you have added them you can access them from code in the ViewController.

For reading files I recommend this code extracted from a StackOverflow response (in English)

Swift 3.0

let file = "file.txt" //this is the file. we will write to and read from it

let text = "some text" //just a text

if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {

    let path = dir.appendingPathComponent(file)

    //writing
    do {
        try text.write(to: path, atomically: false, encoding: String.Encoding.utf8)
    }
    catch {/* error handling here */}

    //reading
    do {
        let text2 = try String(contentsOf: path, encoding: String.Encoding.utf8)
    }
    catch {/* error handling here */}
}

For more info:

link

    
answered by 30.03.2017 в 10:25
-1

You have not tried to use the fmdb framework with the help of cocoapods ??

https://github.com/ccgus/fmdb/blob/master/README.markdown

And for the utilities try to delete the references first and then try to drag the files to the Xcode in the folder where you want them to be located

    
answered by 03.04.2017 в 00:20