Noticed strange behaviour

Using XCode Version 10.1 (10B61)
Making app in Swift
If I have ViewController tittle specified in ViewController Storyboard Attributes Inspector and will try to set SAME title with self.tittle in override func viewDidLoad() - Im getting EMPTY tittle...
I have array with some words, to replace tittle in some cases.
Just noticed on some views I have empty tittles, spend about hour to figureout why that happens.
Is it comes from latest XCode update?

Replies

How do you use the title once you have set it ?


It works ; I have a viewController with initial title in Interface Builder : With Collection View


I do this


    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        print(self.title!)
        self.title = "Changed Title"
        print(self.title!)
    }


I get

With Collection View

Changed Title


Note: title is with a single "t" not tittle



Could you show the code, notably the array, how you set title, how you use the title once set, … :

I have array with some words, to replace tittle in some cases.

Just noticed on some views I have empty tittles, spend about hour to figureout why that happens.

I use exact the same code as you provided
Let's say ViewController title is "Home" (Attributes Inspector->View Controller section->Title)


In this case, I'll get empty title

    override func viewDidLoad() {  
        super.viewDidLoad()  
  
        // Do any additional setup after loading the view.  
        print(self.title!)  
        self.title = "Home"  
        print(self.title!)  
    } 


But this one will work just fine, since stored name is not equal to a new one

    override func viewDidLoad() {  
        super.viewDidLoad()  
  
        // Do any additional setup after loading the view.  
        print(self.title!)  
        self.title = "MyHome"  
        print(self.title!)  
    } 


I workaround it, no problem If you try to put same value to attribute, it just become empty...

Really weird issue, like in Sci Fi time travel warning "Do not touch younger you in the past" 🙂

Can you copy here what you get exactly as a result of the print statements ?

Is it exactly the code you test (not something you edited in the forum) ?


I set the VC title to Home in IB

When I test this

    override func viewDidLoad() {   
        super.viewDidLoad()   
   
        // Do any additional setup after loading the view.   
        print(self.title!)   
        self.title = "Home"   
        print(self.title!)   
    }


I get

Home

Home


If I keep the same IB title but change to

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        print(self.title!)
        self.title = "MyHome"
        print(self.title!)
    }

I get

Home

MyHome

You said in your OP


I have array with some words, to replace tittle in some cases.


Could you show how exactly you are using this array to set the title ?