Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

swift
communitycreator

What is the dictionary.count property in Swift?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The count property of a dictionary in Swift is used to get the number of key-value pairs in a dictionary.

Syntax

dictionary.count

Return Value

It returns an integer. This integer represents the number of key-value pairs of the dictionary.

Example

// create a dictionay
var techGiants = [
"G" : "Google",
"N" : "Netflix",
"Ap" : "Apple",
"Am" : "Amazon",
"M" : "Meta"
]
// print the count
print(techGiants.count)
Get the Number of Entries of a dictionary in Swift

Explanation

  • Line 2: We create a dictionary techGiants and populate it with entries.

  • Line 11: We get the number of entries of the dictionary using the count property and then print the result to the console.

RELATED TAGS

swift
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring