swift 3.1 reading CSV or PLIST file from web












0














I'd like to use readStringFromURL method to obtain a file from a plist and then use it on insertDataInArrayFromPlist in order to display it or put it on CoreData, substituting let path = Bundle.main.path(forResource: plistFileName, ofType: plistFileExtension).



the ISSUE the try statement gives me this ERROR



Argument labels '(contentsOfURL:, usedEncoding:)' do not match any available overloads


in my viewDidLoad:



let obtainedfile = readStringFromURL(stringURL: kremoteSamplePlist)
print(obtainedfile ?? "nothing to print")


I retrive the file from web



   func readStringFromURL(stringURL:String)-> String!{
if let url = NSURL(string: stringURL) {
do {
return try String(contentsOfURL: url, usedEncoding: nil)
} catch {
print("Cannot load contents")
return nil
}
} else {
print("String was not a URL")
return nil
}
}


then I put the data in a struct



func insertDataInArrayFromPlist(arrayOfEntities: inout [product]) {

let path = Bundle.main.path(forResource: plistFileName, ofType: plistFileExtension)
let localArray = NSArray(contentsOfFile: path!)!
for dict in localArray {
var futureEntity = product()
let bdict = dict as! [String: AnyObject]
futureEntity.name = bdict["Name"] as? String
futureEntity.ProductId = bdict["Product Id"] as? String
arrayOfEntities.append(futureEntity)
}

for element in arrayOfEntities {
print("name is (element.name!), the id is (element.ProductId!)")
}

}









share|improve this question






















  • return try String(contentsOf: url, usedEncoding:nil) ?
    – Larme
    Mar 28 '17 at 16:00










  • tried, but I need to modify in return try String(contentsOf: url as URL, usedEncoding: nil) and got this error : Cannot pass immutable value of type '_' as inout argument
    – biggreentree
    Mar 28 '17 at 16:06
















0














I'd like to use readStringFromURL method to obtain a file from a plist and then use it on insertDataInArrayFromPlist in order to display it or put it on CoreData, substituting let path = Bundle.main.path(forResource: plistFileName, ofType: plistFileExtension).



the ISSUE the try statement gives me this ERROR



Argument labels '(contentsOfURL:, usedEncoding:)' do not match any available overloads


in my viewDidLoad:



let obtainedfile = readStringFromURL(stringURL: kremoteSamplePlist)
print(obtainedfile ?? "nothing to print")


I retrive the file from web



   func readStringFromURL(stringURL:String)-> String!{
if let url = NSURL(string: stringURL) {
do {
return try String(contentsOfURL: url, usedEncoding: nil)
} catch {
print("Cannot load contents")
return nil
}
} else {
print("String was not a URL")
return nil
}
}


then I put the data in a struct



func insertDataInArrayFromPlist(arrayOfEntities: inout [product]) {

let path = Bundle.main.path(forResource: plistFileName, ofType: plistFileExtension)
let localArray = NSArray(contentsOfFile: path!)!
for dict in localArray {
var futureEntity = product()
let bdict = dict as! [String: AnyObject]
futureEntity.name = bdict["Name"] as? String
futureEntity.ProductId = bdict["Product Id"] as? String
arrayOfEntities.append(futureEntity)
}

for element in arrayOfEntities {
print("name is (element.name!), the id is (element.ProductId!)")
}

}









share|improve this question






















  • return try String(contentsOf: url, usedEncoding:nil) ?
    – Larme
    Mar 28 '17 at 16:00










  • tried, but I need to modify in return try String(contentsOf: url as URL, usedEncoding: nil) and got this error : Cannot pass immutable value of type '_' as inout argument
    – biggreentree
    Mar 28 '17 at 16:06














0












0








0


0





I'd like to use readStringFromURL method to obtain a file from a plist and then use it on insertDataInArrayFromPlist in order to display it or put it on CoreData, substituting let path = Bundle.main.path(forResource: plistFileName, ofType: plistFileExtension).



the ISSUE the try statement gives me this ERROR



Argument labels '(contentsOfURL:, usedEncoding:)' do not match any available overloads


in my viewDidLoad:



let obtainedfile = readStringFromURL(stringURL: kremoteSamplePlist)
print(obtainedfile ?? "nothing to print")


I retrive the file from web



   func readStringFromURL(stringURL:String)-> String!{
if let url = NSURL(string: stringURL) {
do {
return try String(contentsOfURL: url, usedEncoding: nil)
} catch {
print("Cannot load contents")
return nil
}
} else {
print("String was not a URL")
return nil
}
}


then I put the data in a struct



func insertDataInArrayFromPlist(arrayOfEntities: inout [product]) {

let path = Bundle.main.path(forResource: plistFileName, ofType: plistFileExtension)
let localArray = NSArray(contentsOfFile: path!)!
for dict in localArray {
var futureEntity = product()
let bdict = dict as! [String: AnyObject]
futureEntity.name = bdict["Name"] as? String
futureEntity.ProductId = bdict["Product Id"] as? String
arrayOfEntities.append(futureEntity)
}

for element in arrayOfEntities {
print("name is (element.name!), the id is (element.ProductId!)")
}

}









share|improve this question













I'd like to use readStringFromURL method to obtain a file from a plist and then use it on insertDataInArrayFromPlist in order to display it or put it on CoreData, substituting let path = Bundle.main.path(forResource: plistFileName, ofType: plistFileExtension).



the ISSUE the try statement gives me this ERROR



Argument labels '(contentsOfURL:, usedEncoding:)' do not match any available overloads


in my viewDidLoad:



let obtainedfile = readStringFromURL(stringURL: kremoteSamplePlist)
print(obtainedfile ?? "nothing to print")


I retrive the file from web



   func readStringFromURL(stringURL:String)-> String!{
if let url = NSURL(string: stringURL) {
do {
return try String(contentsOfURL: url, usedEncoding: nil)
} catch {
print("Cannot load contents")
return nil
}
} else {
print("String was not a URL")
return nil
}
}


then I put the data in a struct



func insertDataInArrayFromPlist(arrayOfEntities: inout [product]) {

let path = Bundle.main.path(forResource: plistFileName, ofType: plistFileExtension)
let localArray = NSArray(contentsOfFile: path!)!
for dict in localArray {
var futureEntity = product()
let bdict = dict as! [String: AnyObject]
futureEntity.name = bdict["Name"] as? String
futureEntity.ProductId = bdict["Product Id"] as? String
arrayOfEntities.append(futureEntity)
}

for element in arrayOfEntities {
print("name is (element.name!), the id is (element.ProductId!)")
}

}






ios csv core-data swift3 plist






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 '17 at 15:56









biggreentree

47321023




47321023












  • return try String(contentsOf: url, usedEncoding:nil) ?
    – Larme
    Mar 28 '17 at 16:00










  • tried, but I need to modify in return try String(contentsOf: url as URL, usedEncoding: nil) and got this error : Cannot pass immutable value of type '_' as inout argument
    – biggreentree
    Mar 28 '17 at 16:06


















  • return try String(contentsOf: url, usedEncoding:nil) ?
    – Larme
    Mar 28 '17 at 16:00










  • tried, but I need to modify in return try String(contentsOf: url as URL, usedEncoding: nil) and got this error : Cannot pass immutable value of type '_' as inout argument
    – biggreentree
    Mar 28 '17 at 16:06
















return try String(contentsOf: url, usedEncoding:nil) ?
– Larme
Mar 28 '17 at 16:00




return try String(contentsOf: url, usedEncoding:nil) ?
– Larme
Mar 28 '17 at 16:00












tried, but I need to modify in return try String(contentsOf: url as URL, usedEncoding: nil) and got this error : Cannot pass immutable value of type '_' as inout argument
– biggreentree
Mar 28 '17 at 16:06




tried, but I need to modify in return try String(contentsOf: url as URL, usedEncoding: nil) and got this error : Cannot pass immutable value of type '_' as inout argument
– biggreentree
Mar 28 '17 at 16:06












1 Answer
1






active

oldest

votes


















0














Theres a library available via Cocoapods, CSV.swift by Yaslab. Allows you to import a csv directly in Swift code and convert to a data type of your own. Does the job for me.



https://github.com/yaslab/CSV.swift






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',
    autoActivateHeartbeat: false,
    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%2f43074372%2fswift-3-1-reading-csv-or-plist-file-from-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









    0














    Theres a library available via Cocoapods, CSV.swift by Yaslab. Allows you to import a csv directly in Swift code and convert to a data type of your own. Does the job for me.



    https://github.com/yaslab/CSV.swift






    share|improve this answer


























      0














      Theres a library available via Cocoapods, CSV.swift by Yaslab. Allows you to import a csv directly in Swift code and convert to a data type of your own. Does the job for me.



      https://github.com/yaslab/CSV.swift






      share|improve this answer
























        0












        0








        0






        Theres a library available via Cocoapods, CSV.swift by Yaslab. Allows you to import a csv directly in Swift code and convert to a data type of your own. Does the job for me.



        https://github.com/yaslab/CSV.swift






        share|improve this answer












        Theres a library available via Cocoapods, CSV.swift by Yaslab. Allows you to import a csv directly in Swift code and convert to a data type of your own. Does the job for me.



        https://github.com/yaslab/CSV.swift







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 12:10









        Luke Smith

        623510




        623510






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43074372%2fswift-3-1-reading-csv-or-plist-file-from-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







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            Npm cannot find a required file even through it is in the searched directory