Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
How can I show the number of all the instances of all classes in a category?
Last updated at 2:03 am UTC on 14 December 2021

Answer:

Substitute the desired category for MyCategory-Subcategory, select everything and DoIt.
| totalNumberOfAllInstances |
Transcript clear.
totalNumberOfAllInstances _ (SystemOrganization listAtCategoryNamed: 'MyCategory-Subcategory')
	inject: 0
	into:
		[:sum :each | | numberOfCurrentClassInstances |
		numberOfCurrentClassInstances _ (Smalltalk classNamed: each) allInstances size.
		Transcript
			show: each asString , ': ';
			show: numberOfCurrentClassInstances;
			cr.
		sum _ sum + numberOfCurrentClassInstances].
Transcript cr; show: 'Total: ' , totalNumberOfAllInstances asString