Document Provider Tutorial

Hi all,

I have been going through this tutorial and it is all well and good up to the point of running CleverNote. It runs okay, but Picker does not show up anywhere as an option when it is run.

Also, I’m wondering if some of this lesson is outdated?

My aim is to simply load a text file into my app, which will be used only until the app is closed, I don’t need to send anything out of the app, or make anything within the app available to other apps. Perhaps there is a simpler way to achieve that than what is in this tutorial?



P.S. For some reason I couldn’t create this topic in the Official Tutorials section, so apologies if this is in the wrong place.

From hackingwithswift

    if let filepath = Bundle.main.path(forResource: "myfile", ofType: "txt") {
        do {
            let contents = try String(contentsOfFile: filepath)
        } catch {
            // contents could not be loaded
    } else {
        // example.txt not found!

If you create a file called myfile.txt somewhere in your project, then that code will read the contents of the file.

Cheers for that, 7stud. I’ll play around with that, but I’m really looking to be able to import a file from another app. I have a bit of familiarity with setting up an image picker to import photos, but I’ve been struggling to find info, or a tutorial, on importing files. I have purchased several books and courses on Swift, and not one of them deals with document pickers. I subscribed to hoping there’d be a tutorial here on setting up a document picker, but it looks like there isn’t one. Still, it seems to be a pretty good site so I’ll probably stay subscribed.

This topic was automatically closed after 166 days. New replies are no longer allowed.