0

anyone could please help me figure this out? I am new to Swift and sqlite.

I am passing this string to a function

let compositionstring = "iris, magenta, iris";

Where I convert it to an array with

let compositionArr = string.components(separatedBy: ",")

Then I am expecting the following code to query a database and print the path, filename, and category for each in compositionstring.

       do {
        try compositionArr.forEach {
            print($0)
            
            for var files in try db.prepare(files.select(path, name, category).filter(category.like($0)).limit(1)) {
                print("path: \(files[path]), filename: \(files[name]), category: \(files[category])")

            }

        }

But I only get the first result, and nothing after.

iris

path: file://localhost/Volumes/IWL%20Jen%20Vid/IWL%20Captions/Material_Sonia/Sonia%202019/IWL%20videos/Mexico/Palacio%20belle%20arte/IMG_7762.MOV, filename: IMG_7762.MOV, category: Iris

magenta

iris

There must be something very basic I am missing. Thank you for your help!

1 Answer 1

1

The reason may be that there is no matching for the other items so for loop doesn't run as of empty result from db.prepare......

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your suggestion, but its not it. If I manually enter the 2nd entry from the array and run it, I do get a result. path: file://localhost/Volumes/IWL%20Jen%20Vid/IWL%20Captions/Material_Bernhard/Bernhard%20June%202018/IMG_1968.MOV, filename: IMG_1968.MOV, category: Magenta magenta
from your string there is a space -magenta not magenta ? can you try it also separately and see ?
Yes, thats the solution! Thank you Sh_Khan

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.