ios - Global variables in swift do not change -


i created couple global variables app load image string. when try change value stay same however. value doesn't change after didselectrowatindexpath method called still "initial".

import uikit  var teststring = "initial"  class subjectsviewcontroller: uiviewcontroller {  .....      func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {         tableview.deselectrowatindexpath(indexpath, animated: true)          imagefiles[indexpath.row].getdatainbackgroundwithblock { imagedata, error in             if (error == nil) {                 selectedphoto = uiimage(data: imagedata)!                 println("should change variables")                 teststring = "testing"                 println("no error in fetching image")             } else {                 println("there error getting image")             }         }          self.performseguewithidentifier("detailsegue", sender: self)     } 

create class hold global variables of application

 class globalvariables : nsobject {        var teststring = "initial"     }     var global = globalvariables() 

so in class use code

 if (error == nil) {                 selectedphoto = uiimage(data: imagedata)!                 println("should change variables") // global variable work , value not remove until application close , , change until y                              global.teststring = "testing"                 println("no error in fetching image") 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -