Simple and Elegant Range(A,B) to Range(P,Q) mapper in less then five lines of code.

Overview

HSRange

CI Version

Description

HSRange

HSRangeConvertor Simple and Elegant Range[A,B] to Range[P,Q] mapper in less then three lines of code. E.g. Suppose we have Range[10,90] and Range[20,80], Value 60 of Range[10,90] will be mapped to value 57.5 of Range[20,80].

HSColorRangeConvertor Simple and Elegant Range[A,B] to ColorRange[Color1, Color2] mapper in less then five lines of code.

Demo

HSRange HSColorRange

Example Project

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Swift XCode Tag/Pod version
4.0 to 5.4 9.0 to 12 5.4.0
3.x >= 8.x 1.1

How to use HSRange | HSRangeConvertor?

  1. Create object of HSRangeConverter by passing two object of HSRange
    • Object of first range [A,B]
    • Object of second range [P,Q]
  2. Convert your value from one range to other range.
let firstRange = HSRange(low: 10, high: 80)
let secondRange = HSRange(low: 0.5, high: 0.9)

//Step1:
let rangeConverter = HSRangeConverter(range1: firstRange, range2: secondRange)  
        
//Step2:        
let valueInFirstRange = rangeConverter.toRange2(of: 45) //this will give 0.7
let valueInSecondRange = rangeConverter.toRange1(of: 0.9) //this will give 80

How to use HSColorRange | HSColorRangeConvertor?

Check the demo project. Its has identical steps as above example, just second range is a range of two colors instead of two double values.

Installation

HSRange is available through CocoaPods. To install it follow below steps.

  1. simply add the following line to your Podfile:
pod 'HSRange'
  1. Open terminal, change your current directory to project directory using cd.
  2. Install pod.
pod install
Possible Error:

[!] Unable to find a specification for 'HSRange'

Solution:
pod setup

Major Release

pod version 5.4.0 support swift 4 and swift 5 both as well XCode9 to XCode12 all versions.

Author

Hitendra Solanki, [email protected] | twitter: @hitendrahckr

License

HSRange is available under the MIT license. See the LICENSE file for more info.

You might also like...
Simple JSON Object mapping written in Swift

ObjectMapper ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects (classes and structs) to and from J

Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift

EVReflection General information At this moment the master branch is tested with Swift 4.2 and 5.0 beta If you want to continue using EVReflection in

A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.

MJExtension A fast, convenient and nonintrusive conversion framework between JSON and model. 转换速度快、使用简单方便的字典转模型框架 📜 ✍🏻Release Notes: more details Co

A protocol to serialize Swift structs and classes for encoding and decoding.
A protocol to serialize Swift structs and classes for encoding and decoding.

Serpent (previously known as Serializable) is a framework made for creating model objects or structs that can be easily serialized and deserialized fr

Argo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend
Argo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend

Argo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend. Using Argo

HandyJSON is a framework written in Swift which to make converting model objects to and from JSON easy on iOS.

HandyJSON To deal with crash on iOS 14 beta4 please try version 5.0.3-beta HandyJSON is a framework written in Swift which to make converting model ob

JSONHelper - ✌ Convert anything into anything in one operation; JSON data into class instances, hex strings into UIColor/NSColor, y/n strings to booleans, arrays and dictionaries of these; anything you can make sense of!

JSONHelper Convert anything into anything in one operation; hex strings into UIColor/NSColor, JSON strings into class instances, y/n strings to boolea

ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects to and from JSON.

ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects (classes and structs) to and from J

YamlSwift - Load YAML and JSON documents using Swift

YamlSwift parses a string of YAML document(s) (or a JSON document) and returns a Yaml enum value representing that string.

Releases(5.4.0)
Owner
Hitendra Hckr
quick learner, developer by passion, blogger by public demand
Hitendra Hckr
A simple solution to show a toast message by writing single one line of code

easySwiftToast A very simple solution to show a toast message by writing single one line of code. Installation easySwiftToast is available through Coc

wajeehulhassan 7 May 13, 2022
macOS app to generate Swift 5 code for models from JSON (with Codeable)

SwiftyJSONAccelerator - MacOS app Codeable Model file Generator For Swift 5 Version v2.2 Generate initializer function for classes Application Downloa

Karthikeya Udupa 929 Dec 6, 2022
Codable code is a Swift Package that allows you to convert JSON Strings into Swift structs

Codable code is a Swift Package that allows you to convert JSON Strings into Swift structs.

Julio Cesar Guzman Villanueva 2 Oct 6, 2022
Decodable Simple and strict, yet powerful object mapping made possible by Swift 2's error handling.

Decodable Simple and strict, yet powerful object mapping made possible by Swift 2's error handling. Greatly inspired by Argo, but without a bizillion

Johannes Lund 1k Jul 15, 2022
Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable

Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable. Elevate should no longer be used for

Nike Inc. 611 Oct 23, 2022
An extremely simple JSON helper written in Swift.

Alexander Alexander is an extremely simple JSON helper written in Swift. It brings type safety and Foundation helpers to the cumbersome task of JSON u

HODINKEE 36 Sep 15, 2022
Simple service locator infrastructure for swift

ServiceLocator Simple service locator infrastructure. Pass around protocols backed by these locators to your view controllers and coordinators to simp

CoreSwift 3 Feb 14, 2022
A simple educational application for the game Connect Four for two players

Connect4Game A simple educational application for the game Connect Four for two players. The algorithm checks the match of 4 tiles horizontally, verti

NIKOLAY NIKITIN 0 Oct 20, 2022
A Simple Alert For Swift

JoeSimpleAlert Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation Joe

null 0 Nov 30, 2021
Simple implementation of asset management app UI using swiftUI

MyAssets (자산관리 앱 만들기) swiftUI를 이용하여 자산관리 앱 UI를 간략하게 구현 (swiftUI를 익히기 위함) 초기 화면 1. Tab bar 구현 자산, 추천, 알람, 설정 탭 구현 2. Navigation bar 구현 1) leading에 titl

null 0 Dec 9, 2021