Usama Azam
Usama Azam

Reputation: 433

How to find count of all ViewControllers in Xcode Storyboard?

I have and old Xcode project with too many ViewControllers in one Storyboard. Is there a shortcut way to know the count of all ViewControllers in a Storyboard? Xcode version is 11.2.1.

Upvotes: 2

Views: 510

Answers (2)

Niki Trivedi
Niki Trivedi

Reputation: 1786

Well it's not the perfect way but, I've find a work around to get the count on my own as i like to code for Auto Layout. I hope it helps you too.

  1. Right click on storyboard -> open as Source code

  2. search following text in editor = sceneMemberID="viewController"

this will give you search count just like any editor including table and collection view controller as all have the same sceneMemberId, please find attachment to get a clear view.

enter image description here

Upvotes: 0

staticVoidMan
staticVoidMan

Reputation: 20234

You could use the terminal to run a grep command to search some string:

grep -r -c --include \*.storyboard sceneID .

in form:

grep -r -c --include [pattern] [search string] [search path]
  • -r to search recursively
  • -c to show count
  • --include [pattern] to search in files that match the given pattern, such as:
    • --include \*.storyboard to search all files with storyboard extension
    • --include \Main.storyboard to search in files named Main.storyboard only
  • [search string] is the string to search for. Example:
    • sceneID seems to be a good enough search parameter to locate all the viewControllers, even those that don't have a class associated
  • [search path] to specify where to search from. Example:
    • . to search from current folder; you should be in the project's base folder for better search results

The output should look like:

.../Main.storyboard:12

where 12 is the number of scenes in Main.storyboard

Upvotes: 4

Related Questions