swift 2.0 how to get the name of the image loaded by background_ on the screen

import UIKit import Foundation

class ViewController: UIViewController {

var startTimer0003: NSTimer! //background ΠΏΠ΅Ρ€Π²ΠΈΡ‡Π½Ρ‹ΠΉ запуск weak var startTimer0004: NSTimer! //backgraund ΠΈΠ½Ρ‚Π΅Ρ€Π²Π°Π»Ρ‹ ΠΏΠΎΠ²Ρ‚ΠΎΡ€ΠΎΠ² override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.startTimer0003 = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "runMe0002",userInfo:nil,repeats: false) //background ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ запуск self.startTimer0004 = NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: "runMe0002",userInfo:nil,repeats: true) //background ΠΈΠ½Ρ‚Π΅Ρ€Π²Π°Π» ΠΏΠΎΠ²Ρ‚ΠΎΡ€Π° } /*************************************************************/ // xCode ΠΌΠ°Ρ€ΠΊΠΈ 7.2 // запуск Π½Π° iPhone 6+ /********************** background *************************/ weak var imBackGroundView: UIImageView? func runMe0002() { if(self.imBackGroundView == nil) { self.view.backgroundColor = UIColor(patternImage: UIImage(named: background[0])!) //background = массив Ρ‚ΠΈΠΏ String, для ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ бСрСтся Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΎΠ΄Π½ΠΎ [0] Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ } let imageBackground = UIImage.init(named: background[0]) // всС значСния для ΠΏΡ€ΠΎΠ±Ρ‹ Π½Π° ΠΎΡ‚ΠΊΠ»ΠΈΠΊ let imageBackground0002 = self.view.backgroundColor! let image0002 = UIImage.init(named: background[0]) // let image0002 = UIImage.init(named: "bk0002.jpg") //ΠΏΡ€ΠΎΠ±Π° ΠΏΠΎ Π·Π½Π°Ρ‡Π΅Π½ΠΈΡŽ image let imageBackGroundColor = UIImage.init(named: background[0]) /*********************** switch *******************************************/ switch (self.view.backgroundColor)! // ΠΈΠ»ΠΈ ΠΏΡ€ΠΎΠ±Π° ΠΈΠ· списка ΠΎΡ‚ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Ρ… = всС ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²ΠΎ... // switch (UIColor(patternImage: UIImage(named: background[0])!)) // switch (self.view.backgroundColor! = UIColor(pattertnImage: UIImage(named: background[0]))!) { // 0 case (self.view.backgroundColor)! === image0002: print("view.backgroundColor works_0") //0.1 case self.view.backgroundColor! !== UIImage!(imageBackground!): print("view.backgroundColor works_0.1") //0.2 case self.view.backgroundColor! !== UIColor(patternImage: (UIImage?(imageBackground!)!)!): print("view.backgroundColor works_0.2") //0.3 case imageBackGroundColor !== "bk0002.jpg": print("It works_0.3") //0.4 case image0002! : print("It works_0.4") //0.5 case UIColor(patternImage: (UIImage?(imageBackground!)!)!): print("It works_0.5") //0.6 case "bk0002.jpg": print("It works_0.6") //0.7 //case background[0]: ОШ String // print("It works_0.7") //0.8 case UIColor(patternImage: (UIImage?(imageBackground!)!)!): print("It works_0.8") //0.9 case UIColor(patternImage: UIImage(named: background[0])!): print("It works_0.9") // 1 case self.view.backgroundColor! != background[0]: print("view.backgroundColor works_1") // 2.0 case self.view.backgroundColor! !== UIImage(named: background[0]): print("view.backgroundColor works_2.0") // 2.1 case self.view.backgroundColor! !== UIImage.init(named: background[0]): print("view.backgroundColor works_2.1") // 2.2 case UIColor(patternImage: UIImage(named: background[0])!) != background[0]: //"bk0002.jpg": print("view.backgroundColor works_2.2") // 2.3 case self.view.backgroundColor! !== UIColor(patternImage: UIImage(named: "bk0002@3x.jpg")!): print("view.backgroundColor works_2.3") // 3 case self.view.backgroundColor! !== UIColor(patternImage: UIImage(named: background[0])!): print("view.backgroundColor works_3") // 4 case UIColor(patternImage: UIImage(named: background[0])!) !== true: print("view.backgroundColor works_4") // 5 case UIColor(patternImage: UIImage(named: background[0])!) !== 0: print("view.backgroundColor works_5") // 6 case UIColor(patternImage: UIImage(named: background[0])!) !== "bk0002.jpg": print("view.backgroundColor works_6") // 7 case UIColor(patternImage: UIImage(named: background[0])!) !== "bk0002@3x.jpg": print("view.backgroundColor works_7") // 8 case self.view.backgroundColor! != UIImage(named: "bk0002@3x.jpg")!: print("view.backgroundColor works_8") // 9 case imBackGroundView == background[0]: print("view.backgroundColor works_9") // 9.1 case self.imBackGroundView != background[0]: print("view.backgroundColor works_9.1") // 10 case self.imBackGroundView != UIImage(named: background[0]): print("view.backgroundColor works_10") // 11 case self.imBackGroundView === UIColor(patternImage: UIImage(named: background[0])!): print("view.backgroundColor works_11") // 12 case self.imBackGroundView === UIImage(named: "bk0002.jpg"): print("view.backgroundColor works_12") // 13 case self.imBackGroundView !== self.view.backgroundColor: print("view.backgroundColor works_13") // 14 case self.imBackGroundView !== UIColor(patternImage: UIImage(named: background[Int(arc4random_uniform(UInt32(background.count)))])!): print("view.backgroundColor works_14") // 15.0 // case self.view.backgroundColor!.isEqual(UIColor(patternImage: UIImage?(named: image0002))): case self.view.backgroundColor!.isEqual(UIColor(patternImage: (UIImage!(image0002))!)): print("view.backgroundColor works_15.0") // 15.1 case self.view.backgroundColor!.isEqual(UIColor(patternImage: (UIImage.init(named: background[0]))!)): print("view.backgroundColor works_15.1") // 15.2 // case (UIColor(patternImage: UIImage(named: background[0]))!) isEqual image0002: // = ОШ // print("view.backgroundColor works_15.2") // 16 //case self.view.backgroundColor?.isEqual (UIColor(patternImage: (UIImage!(named: background[0]))!)): //case self.view.backgroundColor!.isEqual(UIColor!(patternImage: UIImage!(named: "bk0002.jpg"))!): //case self.view.backgroundColor!.isEqual(UIColor(patternImage: (UIImage!("bk0002@3x.jpg"))!)): // print("view.backgroundColor works_16") default : print("view.backgroundColor no result") // всС ΠΏΡ€ΠΈΠ½Ρ‚ ΠΈΠ΄ΡƒΡ‚ Π² консоль... } //скобка закрытия switch ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ /*********************** **************************/ startTimer0003.invalidate() // startTimer0004.invalidate() } // скобка func runME0002 override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } 

} // compile - there will be a link to ya.disk


 weak var imBackGroundView: UIImageView? // = imageBackground func runMe0002() { var imageBackground = UIImage(named: background[Int(arc4random_uniform(UInt32(background.count)))]) if imageBackground! != UIImage(named: background[0]) { print("imageBackground works_0") } else { print("view.backgroundColor no result") } //скобка закрытия if if(self.imBackGroundView == nil) { self.view.backgroundColor = UIColor(patternImage: UIImage!(imageBackground)) } //скобка if (self.imBackGroundView == nil) 

} // bracket func runMe0002 ()

  • either I did not understand the question, or the answer cannot be done, after the image is loaded into the memory, the system itself does not know where the image came from - Max Mikheyenko
  • I have long suspected that all is not well in the Danish kingdom ... but these things can not be stuck =? func imagePickerController (picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: AnyObject]) {... and just func pickerView (pickerView: UIPickerView !, didSelectRow row: Int, inComponent component: Int) ... because the system takes an array from an array, didn’t chooseRow row: Int, inComponent component: Int) because it is retrieved from an array by the array, byCeponEtRow row: Int, inComponent component: Int) because it is retrieved from an array by the array, it is taken from the array by the array, from Component Component Int: in, inComponent component: Int) because it is taken from the array by the array from the array, byCeponentRow row: Int, inComponent component: Int) ... ... I don’t have to have a file name - it’s enough by the numerical value ... for how long I’m trying to slip somehow, but nothing good came out ... @ Max Mikheyenko - user198638

1 answer 1

Standardly this functionality is not provided. And if the image is displayed, the file name cannot be obtained, plus not the fact that the image is from a file, maybe it is downloaded from the network.

But you can create a variable and store in it the name of the file you take. You can create your own class inherited from a UIImage and specify the file name in the class field.

  • I tried the recipe = for some reason, it works the other way around. if the condition background [0] is not met - print ("imageBackground works_0") and if the condition is met i.e. The necessary value is loaded into the background of the screen - background [0] - print ("view.backGroundColor no result") = it happens =? and more on this advice - is there anything like an example or similar ... @ VAndkJ - user198638