Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

swift
communitycreator

What is the lowerBound property of a range 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 lowerBound property of the range instance in Swift is used to get the lowest value or the starting point of a range. It is equivalent to the range’s lower bound.

Syntax

range.lowerBound

Return value

The value returned is an integer and is the lowest range value.

Code

// create some ranges
let range1 = 1 ..< 6 // 1 to 5
let range2 = 10 ..< 50 // 10 to 49
let range3 = 0 ..< 0 // empty
let range4 = 3 ..< 3 // empty
// get the lower bounds of a ranges
print(range1.lowerBound)
print(range2.lowerBound)
print(range3.lowerBound)
print(range4.lowerBound)
Get the lower bounds of ranges in Swift

Explanation

In the code above:

  • Lines 2–5: We create range variables.
  • Lines 8–11: We print the lower bounds of the ranges 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