UIImage and switch case

Hey guys! I´m a absolute beginner in Swift. And actualy i try some simple thinks in a small app. Here you would see a Table View with files in "iTunes files". With some pathExtension like PDF, PNG, JPG or without a extension you´ll see a folder.


My problem: The screen shows every single file or folder. And it is possible for me to show exactly one image: An Folder image, PDF image or whatever. But it isn´t possible to let the code deside. An example:


cell.imageView?.image = UIImage(named: "folderImage.png")


Here is a Cell mit the name "cell". And he print a UIImage named "folderImage.png". But evey file like a "png", jpg" or whatever becomes the folder image too. The whole day i try things like this:


let fileExtension = (input as NSString).pathExtension

cell.imageView?.image = UIImage(named: 

switch fileExtension {

     case "pdf":
          "pdfImage.png"
     case "rtf":
          "rtfImage.png"
     ...
     default:
          "folderImage.png"

     }

)


Please please help me! 😟 What is to do, that these output in "extension ViewController: UITableViewDataSource" choose the image by hisself.


Thank you very much!

Replies

Please show some examples of `input`. Does it contain a full path to a file or a folder? Or just the file/folder name with extension?

And, please clarify, what do you expect the result should be, for `input` as "png" or "jpg"?

There can be a folder named "png", a PDF file namd "png"... What do you expect in such cases?

There is a dot in path extension.


So, you should test case ".pdf"

etc


Otherwise, evreything falls in the default case.


Note: I would be surprised it compiles with the switch as named: argument…

Some examples of "input" are:


rtf
png
(without a extension here an empty row)
pdf
jpg


So what i´ll become is exatly the file extension without a ".". I have to evaluate this and show the specific image like a folder for a empty row, a png-Image for "png" or a pdf-Image for a "pdf" ... And i had the hope, that a syntax like


cell.imageView?.image = UIImage(named:   

switch fileExtension {  

     case "pdf":  
          "pdfImage.png"  
     case "rtf":  
          "rtfImage.png"  
     ...  
     default:  
          "folderImage.png"  

     }


will work. :/

Thank you for your support! I tried also ".pdf". But it wouldn´t work for me. :/

What you have shown is an example of `fileExtension`, no? If `input` were such string, all your file extension become "".

One more.


i had the hope, that a syntax like

...

will work. :/


Please show any one of your code you have tried the whole day. Not like this, exact code you have tried.


Pseudo code sometimes helps to represent what you really want to do, but in this case, that is a jamming noise.

Could you show the ral code ?


This is not the real one:


cell.imageView?.image = UIImage(named:    
 
switch fileExtension {   
 
     case "pdf":   
          "pdfImage.png"   
     case "rtf":   
          "rtfImage.png"   
     ...   
     default:   
          "folderImage.png"   
 
     }