Post

Replies

Boosts

Views

Activity

Reply to Set NSImage to variable instead of quoted string for image name
Thanks for helping out. Here is what I am doing://Set the variablevar theIcon:String = ""//Connect the outlet@IBOutlet weak var myAppIcon: NSImageView!//Set name of filelet icon = "icon.txt"//Read the contents of the fileif let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first { let iconURL = dir.appendingPathComponent(icon) do { let myIcon = try String(contentsOf: iconURL, encoding: .utf8) self.theIcon = myIcon print(myIcon) } catch {/* error handling here */} }//Update the UIDispatchQueue.main.async { print("update some UI") self.myAppIcon.image = NSImage(named: self.theIcon) }The file, icon.txt, contains the full name of the file. For example, microsoft.png or printer.png. I can update the file while the app is running and the value is printed to the output window. printers.pngupdate some UIAm i dealing with a new line issue here? Oh my oh my. I am such a doofus. It was the newline! I was using echo to test updating the file and I did not use -n. All along the issue was bad input from the file because I was getting microsoft.png\n not microsoft.png. I am kicking myselft for failing to pay attention to the gapping white space between the logging output.Thank you for making be take a break and also looking at the obvious.
Feb ’20