import data from a txt file from a web









up vote
-1
down vote

favorite












I have the following structure and would like to import the data from a txt file but from a web page instead of the app, is there any way to do it?



I want to access the data through a web address.



if let filePath = Bundle.main.path(forResource: "archivotxt", ofType: "txt") 

do
let contenido = try String(contentsOfFile: filePath)
let fila = contenido.components(separatedBy: "n")
for i in 1..<fila.count
let datosArchivo = fila[i].components(separatedBy: "t")
//print(datosArchivo[1])
let campos = Lista(nom: datosArchivo[0], dir: datosArchivo[1], tel: datosArchivo[2])
self.lista.append(campos)

catch let error as NSError
print("error al leer el archivo", error)


else
print("no existe el archivo")










share|improve this question























  • You download the file first perhaps? Not sure what you're asking here.
    – Joakim Danielson
    Nov 10 at 19:17











  • I don't want to download the file, I want to access the data through a web address.
    – Miquel Molina
    Nov 10 at 19:26










  • How could you possibly do that, to get the data you need to download it? Maybe this is just a confusion around terms, accessing a file via an Url and downloading it is the same thing for me. See this question for a possible solution or this
    – Joakim Danielson
    Nov 10 at 19:32










  • I want the app to access some data from the web that is updated daily, but I do not want the file to be downloaded every time, I want to access the data of a .txt file that is in a web address
    – Miquel Molina
    Nov 10 at 19:35






  • 1




    Hard to help you then.
    – Joakim Danielson
    Nov 10 at 20:37














up vote
-1
down vote

favorite












I have the following structure and would like to import the data from a txt file but from a web page instead of the app, is there any way to do it?



I want to access the data through a web address.



if let filePath = Bundle.main.path(forResource: "archivotxt", ofType: "txt") 

do
let contenido = try String(contentsOfFile: filePath)
let fila = contenido.components(separatedBy: "n")
for i in 1..<fila.count
let datosArchivo = fila[i].components(separatedBy: "t")
//print(datosArchivo[1])
let campos = Lista(nom: datosArchivo[0], dir: datosArchivo[1], tel: datosArchivo[2])
self.lista.append(campos)

catch let error as NSError
print("error al leer el archivo", error)


else
print("no existe el archivo")










share|improve this question























  • You download the file first perhaps? Not sure what you're asking here.
    – Joakim Danielson
    Nov 10 at 19:17











  • I don't want to download the file, I want to access the data through a web address.
    – Miquel Molina
    Nov 10 at 19:26










  • How could you possibly do that, to get the data you need to download it? Maybe this is just a confusion around terms, accessing a file via an Url and downloading it is the same thing for me. See this question for a possible solution or this
    – Joakim Danielson
    Nov 10 at 19:32










  • I want the app to access some data from the web that is updated daily, but I do not want the file to be downloaded every time, I want to access the data of a .txt file that is in a web address
    – Miquel Molina
    Nov 10 at 19:35






  • 1




    Hard to help you then.
    – Joakim Danielson
    Nov 10 at 20:37












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I have the following structure and would like to import the data from a txt file but from a web page instead of the app, is there any way to do it?



I want to access the data through a web address.



if let filePath = Bundle.main.path(forResource: "archivotxt", ofType: "txt") 

do
let contenido = try String(contentsOfFile: filePath)
let fila = contenido.components(separatedBy: "n")
for i in 1..<fila.count
let datosArchivo = fila[i].components(separatedBy: "t")
//print(datosArchivo[1])
let campos = Lista(nom: datosArchivo[0], dir: datosArchivo[1], tel: datosArchivo[2])
self.lista.append(campos)

catch let error as NSError
print("error al leer el archivo", error)


else
print("no existe el archivo")










share|improve this question















I have the following structure and would like to import the data from a txt file but from a web page instead of the app, is there any way to do it?



I want to access the data through a web address.



if let filePath = Bundle.main.path(forResource: "archivotxt", ofType: "txt") 

do
let contenido = try String(contentsOfFile: filePath)
let fila = contenido.components(separatedBy: "n")
for i in 1..<fila.count
let datosArchivo = fila[i].components(separatedBy: "t")
//print(datosArchivo[1])
let campos = Lista(nom: datosArchivo[0], dir: datosArchivo[1], tel: datosArchivo[2])
self.lista.append(campos)

catch let error as NSError
print("error al leer el archivo", error)


else
print("no existe el archivo")







ios json






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 19:26

























asked Nov 10 at 19:04









Miquel Molina

14




14











  • You download the file first perhaps? Not sure what you're asking here.
    – Joakim Danielson
    Nov 10 at 19:17











  • I don't want to download the file, I want to access the data through a web address.
    – Miquel Molina
    Nov 10 at 19:26










  • How could you possibly do that, to get the data you need to download it? Maybe this is just a confusion around terms, accessing a file via an Url and downloading it is the same thing for me. See this question for a possible solution or this
    – Joakim Danielson
    Nov 10 at 19:32










  • I want the app to access some data from the web that is updated daily, but I do not want the file to be downloaded every time, I want to access the data of a .txt file that is in a web address
    – Miquel Molina
    Nov 10 at 19:35






  • 1




    Hard to help you then.
    – Joakim Danielson
    Nov 10 at 20:37
















  • You download the file first perhaps? Not sure what you're asking here.
    – Joakim Danielson
    Nov 10 at 19:17











  • I don't want to download the file, I want to access the data through a web address.
    – Miquel Molina
    Nov 10 at 19:26










  • How could you possibly do that, to get the data you need to download it? Maybe this is just a confusion around terms, accessing a file via an Url and downloading it is the same thing for me. See this question for a possible solution or this
    – Joakim Danielson
    Nov 10 at 19:32










  • I want the app to access some data from the web that is updated daily, but I do not want the file to be downloaded every time, I want to access the data of a .txt file that is in a web address
    – Miquel Molina
    Nov 10 at 19:35






  • 1




    Hard to help you then.
    – Joakim Danielson
    Nov 10 at 20:37















You download the file first perhaps? Not sure what you're asking here.
– Joakim Danielson
Nov 10 at 19:17





You download the file first perhaps? Not sure what you're asking here.
– Joakim Danielson
Nov 10 at 19:17













I don't want to download the file, I want to access the data through a web address.
– Miquel Molina
Nov 10 at 19:26




I don't want to download the file, I want to access the data through a web address.
– Miquel Molina
Nov 10 at 19:26












How could you possibly do that, to get the data you need to download it? Maybe this is just a confusion around terms, accessing a file via an Url and downloading it is the same thing for me. See this question for a possible solution or this
– Joakim Danielson
Nov 10 at 19:32




How could you possibly do that, to get the data you need to download it? Maybe this is just a confusion around terms, accessing a file via an Url and downloading it is the same thing for me. See this question for a possible solution or this
– Joakim Danielson
Nov 10 at 19:32












I want the app to access some data from the web that is updated daily, but I do not want the file to be downloaded every time, I want to access the data of a .txt file that is in a web address
– Miquel Molina
Nov 10 at 19:35




I want the app to access some data from the web that is updated daily, but I do not want the file to be downloaded every time, I want to access the data of a .txt file that is in a web address
– Miquel Molina
Nov 10 at 19:35




1




1




Hard to help you then.
– Joakim Danielson
Nov 10 at 20:37




Hard to help you then.
– Joakim Danielson
Nov 10 at 20:37












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I found this, I answer to myself, in case someone is interested



 let datos = "http://misitioweb/archivos/archivotxt.txt"


if let filePath = URL(string: datos)
do
let contenido = try String(contentsOf: filePath)
let fila = contenido.components(separatedBy: "n")
for i in 1..<fila.count
let datosArchivo = fila[i].components(separatedBy: "t")
//print(datosArchivo[1])
let campos = Lista(nom: datosArchivo[0], dir: datosArchivo[1], tel: datosArchivo[2])
self.lista.append(campos)

catch let error as NSError
print("error al leer el archivo", error)


else
print("no existe el archivo")






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242427%2fimport-data-from-a-txt-file-from-a-web%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    I found this, I answer to myself, in case someone is interested



     let datos = "http://misitioweb/archivos/archivotxt.txt"


    if let filePath = URL(string: datos)
    do
    let contenido = try String(contentsOf: filePath)
    let fila = contenido.components(separatedBy: "n")
    for i in 1..<fila.count
    let datosArchivo = fila[i].components(separatedBy: "t")
    //print(datosArchivo[1])
    let campos = Lista(nom: datosArchivo[0], dir: datosArchivo[1], tel: datosArchivo[2])
    self.lista.append(campos)

    catch let error as NSError
    print("error al leer el archivo", error)


    else
    print("no existe el archivo")






    share|improve this answer
























      up vote
      0
      down vote













      I found this, I answer to myself, in case someone is interested



       let datos = "http://misitioweb/archivos/archivotxt.txt"


      if let filePath = URL(string: datos)
      do
      let contenido = try String(contentsOf: filePath)
      let fila = contenido.components(separatedBy: "n")
      for i in 1..<fila.count
      let datosArchivo = fila[i].components(separatedBy: "t")
      //print(datosArchivo[1])
      let campos = Lista(nom: datosArchivo[0], dir: datosArchivo[1], tel: datosArchivo[2])
      self.lista.append(campos)

      catch let error as NSError
      print("error al leer el archivo", error)


      else
      print("no existe el archivo")






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        I found this, I answer to myself, in case someone is interested



         let datos = "http://misitioweb/archivos/archivotxt.txt"


        if let filePath = URL(string: datos)
        do
        let contenido = try String(contentsOf: filePath)
        let fila = contenido.components(separatedBy: "n")
        for i in 1..<fila.count
        let datosArchivo = fila[i].components(separatedBy: "t")
        //print(datosArchivo[1])
        let campos = Lista(nom: datosArchivo[0], dir: datosArchivo[1], tel: datosArchivo[2])
        self.lista.append(campos)

        catch let error as NSError
        print("error al leer el archivo", error)


        else
        print("no existe el archivo")






        share|improve this answer












        I found this, I answer to myself, in case someone is interested



         let datos = "http://misitioweb/archivos/archivotxt.txt"


        if let filePath = URL(string: datos)
        do
        let contenido = try String(contentsOf: filePath)
        let fila = contenido.components(separatedBy: "n")
        for i in 1..<fila.count
        let datosArchivo = fila[i].components(separatedBy: "t")
        //print(datosArchivo[1])
        let campos = Lista(nom: datosArchivo[0], dir: datosArchivo[1], tel: datosArchivo[2])
        self.lista.append(campos)

        catch let error as NSError
        print("error al leer el archivo", error)


        else
        print("no existe el archivo")







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 9:50









        Miquel Molina

        14




        14



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242427%2fimport-data-from-a-txt-file-from-a-web%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto