An Integer type that clamps its value to its minimum and maximum instead of over- or underflowing.

Overview

ClampedInteger

An Integer type that clamps its value to its minimum and maximum instead of over- or underflowing.

Examples

    let big = ClampedInteger.max // 9223372036854775807
    big + 10 == .max // true
    big * 2 == .max // true
    big * -1 == .min + 1 // true, because -.max > .min
    big * -2 == .min // true
    
    let negative = ClampedInteger.min // -9223372036854775808
    negative - 10 == .min // true
    negative * 2 == .min // true
    negative * -1 == .max // true

ClampedInteger is generic over FixedWidthIntegers and can be used with any fixed with integer type:

    let big = ClampedInteger<UInt16>.max
    big + 10 == .max // true

Install

Package.swift

Edit the Package.swift file. Add the GamCenterUI as a dependency:

let package = Package(
    name: " ... ",
    products: [ ... ],
    dependencies: [
        .package(url: "https://github.com/berikv/ClampedInteger.git", from: "0.0.0") // here
    ],
    targets: [
        .target(
            name: " ... ",
            dependencies: [
                "ClampedInteger" // and here
            ]),
    ]
)

For .xcodeproj projects

  1. Open menu File > Add Packages...
  2. Search for "https://github.com/berikv/ClampedInteger.git" and click Add Package.
  3. Open your project file, select your target in "Targets".
  4. Open Dependencies
  5. Click the + sign
  6. Add ClampedInteger
You might also like...
This repo shows how to set up and use GitHub Actions as a CI for Swift Packages
This repo shows how to set up and use GitHub Actions as a CI for Swift Packages

SwiftPackageWithGithubActionsAsCI This repo shows how to set up and use GitHub Actions as a CI for Swift Packages. Available environments on GitHib Li

A simple solution to decrease build time and more cleaner codebase

Swift Optional Optimizer A simple Protocol Oriented solution to decrease build time and more cleaner code base. Are you tired of using ?? in your code

SpaceX rocket listing app using RxSwift and CLEAN Architecture with MVVM
SpaceX rocket listing app using RxSwift and CLEAN Architecture with MVVM

Jibble SpaceX rocket listing app using RxSwift and CLEAN Architecture with MVVM Demo Features Reactive Bindings URL / JSON Parameter Encoding Filter Y

A trivial app for storing and viewing famous quotes

Paraphrase A trivial app for storing and viewing famous quotes This app was specifically designed to accompany a tutorial series about modern app infr

A Swift package that adds some handy functions to String and NSMutableAttributedString

StringBooster StringBooster is a simple Swift package containing a few useful ex

A demo demonstrates how to use combine and MVVM in the SwiftUI app
A demo demonstrates how to use combine and MVVM in the SwiftUI app

SwiftUI-MVVM-Combine A demo demonstrates how to use combine and MVVM in the Swif

This a simple swiftui app where i used mvvm architecture, coredata swiftui and so on..
This a simple swiftui app where i used mvvm architecture, coredata swiftui and so on..

SwiftUI MVVM COREDATA NOTE APP This a simple swiftui app where i used mvvm architecture, coredata swiftui and so on... #FEATURES SWIFTUI MVVM COREDATA

Cryptocurrency price checker, build with UIKit and MVC + Delegate pattern.
Cryptocurrency price checker, build with UIKit and MVC + Delegate pattern.

Coin Check Cryptocurrency price checker. The app fetch from CoinAPI.io the latest coin prices, build with UIKit and MVC + Delegate pattern. Features S

A Swift implementation of a Flickr-search application that uses MVVM and ReactiveCocoa
A Swift implementation of a Flickr-search application that uses MVVM and ReactiveCocoa

ReactiveCocoa, Swift and MVVM This application is a Swift-port of an MVVM / ReactiveCocoa example application I wrote a few months ago. Instructions T

Owner
Berik Visschers
Berik Visschers
Lightweight Framework for using Core Data with Value Types

Features Uses Swift Reflection to convert value types to NSManagedObjects iOS and Mac OS X support Use with structs Works fine with let and var based

Benedikt Terhechte 456 Nov 6, 2022
Tech blog about Put Generic Protocol as Variable Type. How Combine Publisher put into AnyPublisher

How to Put Generic Protocol as Variable Type Have you ever put a Protocol on a variable? I believe you do. The Delegate pattern is using a lot in UIKi

Tsungyu Yu 8 Aug 17, 2021
Compatible backports of commonly used type properties for `URL` that are only available from iOS 16.0+ / macOS 13.0+ / tvOS 16.0+ / watchOS 9.0+.

URLCompatibilityKit URLCompatibilityKit is a lightweight Swift package that adds compatible backports of commonly used type properties, type and insta

Marco Eidinger 17 Dec 8, 2022
iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit

iOS (Swift 5): MVVM test with Combine and UIKit MVVM and functional reactive programming (FRP) are very used in iOS development inside companies. Here

Koussaïla BEN MAMAR 2 Dec 31, 2021
Explanations and samples about the Swift programming language

About Swift Contents Explanations and samples about: Swift Programming Language Swift Standard Library Target audience Developers familiar with object

Nicola Lancellotti - About 74 Dec 29, 2022
👨‍💻Watch the latest and greatest conference videos on your Mac

Conferences.digital is the best way to watch the latest and greatest videos from your favourite developer conferences for free on your Mac. Either sea

Timon Blask 768 Jan 4, 2023
SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

Realm 16.9k Dec 30, 2022
A package to help track how often the user opened the app and if they opened it in the current version before.

AppOpenTracker AppOpenTracker provides an observable AppOpenTracker.shared instance that can be used to track the last version that the app was opened

Florian Schweizer 9 Oct 29, 2022
Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets.

SwiftUI-LazyVGrid Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets. Screenshots Samples IP & Credits All those b

Ethan Halprin 3 Aug 9, 2022
This little app aims to help teach me how to implement more then one API in one single application in a reusable and properly structured manner.

LilAPI App News & Weather This little API app combines two of Jordan Singers Lil Software API's into one app. The goal with this app was to learn how

hallux 1 Oct 13, 2021