Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

swift
string
communitycreator

What is string.underestimatedCount 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

In Swifty, the underestimatedCount property is used to return a value less than or equal to the number of elements in a collection.

Syntax

collection.underestimatedCount

Return value

It returns an integer value, which is less than or equal to the number of elements in the collection.

Example

// create collections
let name = "Theodore"
let greetings = "Edpresso is great!"
let ages = [20, 12, 50, 40]
// invoke the underestimatedCount property
print(name.underestimatedCount)
print(greetings.underestimatedCount)
print(ages.underestimatedCount)
Using the underestimatedCount on collections

Explanation

  • Lines 2–4: We create three collections, two string values name and greetings, and an array ages.
  • Lines 7–9: We invoke the underestimatedCount instance property on the collections. Next, we print the values to the console.

RELATED TAGS

swift
string
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