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")
}
ios json
|
show 4 more comments
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")
}
ios json
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
|
show 4 more comments
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")
}
ios json
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
ios json
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
|
show 4 more comments
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
|
show 4 more comments
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")
}
add a comment |
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")
}
add a comment |
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")
}
add a comment |
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")
}
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")
}
answered Nov 11 at 9:50
Miquel Molina
14
14
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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