post/

Everybody Feels

May 22, 20211 min read

iOS, Swift, Xcode

In creating view controllers, I usually add a custom static property I name identifier. This holds the string representation of the view controller that I usually reference in initializing data from a storyboard.

Here's an example usage on a method to display a scene from a storyboard on a view controller:

func navigateToSettingsScreen() {
  let settingsViewController = self.storyboard?.instantiateViewController(identifier: SettingsViewController.identifier) as? SettingsViewController

  // Assign other stuff here like delegates
  settingsViewController?.delegate = self

  present(settingsViewController!, animated: true, completion: nil)
}

Example SettingsViewController.swift that contains the identifier property:

//
//  SettingsViewController.swift
//  TestApp
//
//  Created by Noel on 3/24/21.
//
import UIKit

class SettingsViewController: UIViewController {
  static let identifier = "SettingsViewController"

  override func viewDidLoad() {
    super.viewDidLoad()

    // Do something here
  }

}

So I did what I thought.

My Spotify is currently offline.