Bug in Swift / Xcode

Something weird is happening? As I tested this on all the simulators including the physical phone, the search bar renders fine. However, when I quit Xcode and open the application on the phone, the search bar would not render with the correct width. (It would be all bunched up. It's hard to debug because this program isn't visible in any of the simulators.) Part of the code:

override func viewDidLoad()
{
super.viewDidLoad()
initList()
}

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        initSearchController()
    }

func initSearchController()
{
searchController.loadViewIfNeeded()
        searchController.searchResultsUpdater = self
        searchController.searchBar.sizeToFit()
        searchController.searchBar.frame.size.width = self.view.frame.size.width

searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.enablesReturnKeyAutomatically = false
searchController.searchBar.returnKeyType = UIReturnKeyType.search
        searchController.isActive = false
        searchController.searchBar.placeholder = "Search poetry, lyrics, arias ..."
        searchController.definesPresentationContext = true
        searchController.searchBar.delegate = self
        navigationItem.searchController = searchController
        navigationItem.hidesSearchBarWhenScrolling = false
}
I cannot reproduce the same issue.

I created a new iOS App project of Storyboard as Interface, copied all the code shown into it. And ran it.
In both actual iOS device and simulators, both run through Xcode or from Home screen, search bar is shown properly.

I guess you are doing something wrong in the hidden parts of your code. Or the issue may happen in very limited conditions.
You may need to find what is wrong or what is the right condition to reproduce this issue.
Bug in Swift / Xcode
 
 
Q