0

In my project I have the following directory structure for Cards:

enter image description here

And in project I create a simple XML file, from where I could control cards that should be loaded.

<?xml version="1.0" encoding="UTF-8"?> <root>
    <flashcards>
       <flashcard>
         <images>
           <image>testcard/testimage1</image>
           <image>testcard/testimage2</image>
         </images>
       </flashcard>
    </flashcards>
</root>

The following part of code that should convert image path to UIImage object

 for xmlFlashcardImage in xmlFlashcard["images"]["image"].all {
                        if let imageName = xmlFlashcardImage.element?.text {
                            if let image = UIImage(named: imageName) {
                                flashCard.images.append(image)
                            } else {
                                #if DEBUG
                                    NSLog("Coudn't load image with path: \(imageName).")
                                #endif
                            }
                        }
                    }

I tried to play with FileManager, but failed too :(

Arti
  • 7,356
  • 12
  • 57
  • 122

1 Answers1

0

You use UIImage(named: imageName) to get the image from your project Assets (Assets.xcassets). Have a look at some of the answers here: Load image from iOS 8 framework

CodeR70
  • 447
  • 3
  • 2
  • The problem that I don't want use default assets folder. I created my own folder and I can't figure out what path do I need to set... I want to set path, not names – Arti Oct 07 '17 at 10:11
  • I want to set path like UIImage("flashcards/testcard/testcard1.png") – Arti Oct 07 '17 at 10:15
  • If you copy the files into your bundle (so they end up in Resources) you can read them using NSBundle. Please read some of the answers, not only the top one. – CodeR70 Oct 07 '17 at 11:11