MQTagged provides a Tagged structure which helps differentiating between values of the same type.

Overview

MQTagged

Platforms Swift Package Manager compatible SwiftVersion

MQTagged provides a Tagged structure which helps differentiating between values of the same type.

Summary

Let's have an example of a function which authorizes a user based on two string parameters:

func authorize(_ username: String, _ password: String) {
  ...
}

It is possible to call the function with swapped arguments without any compiler warning. Using a typealias also does not solves the issue:

typealias Username = String
typealias Password = String

func authorize(_ username: Username, _ password: Password) {
  ...
}

let username: Username = "[email protected]"
let password: Password = "pa55w0rD"

authorize(username, password)
authorize(password, username) // It's wrong but still compiles.

typealias doesn't cause compiler warning or error when type names are not matching since resolved type is the same. MQTagged solution to this problem is to use Tag type:

enum UsernameTag {}
enum PasswordTag {}

typealias Username = Tagged<String, UsernameTag>
typealias Password = Tagged<String, PasswordTag>

func authorize(_ username: Username, _ password: Password) {
  ...
}

Now any call with swapped parameters won't compile.

let username: Username = "[email protected]"
let password: Password = "pa55w0rD"

authorize(username, password)
authorize(password, username) // This won't compile.

Installation

MQTagged can be integrated throught Swift Package Manager. In your Package.swift file add the following dependency:

dependencies: [
  .package(
    url: "https://gitlab.com/miquido/dev/ios/mqtagged.git",
    .upToNextMajor("0.1.0")
  )
]

License

Copyright 2022 Miquido

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You might also like...
WebDomHandling - A Swift Package for handling JavaScript code between WebKit and Swift implemented by WebKit

WebDomHandling A Swift Package for handling JavaScript code between WebKit and S

Calculate your tip and split the bill between any number of people
Calculate your tip and split the bill between any number of people

Calculate your tip and split the bill between any number of people

Bridge between onfido-auth and react-native

react-native-onfido-auth-sdk Table of contents Overview Installation Usage 1. Creating the SDK configuration 2. Parameter details 3. Success Response

An iOS app that resolves issues of dividing the debt between roomates.
An iOS app that resolves issues of dividing the debt between roomates.

An iOS app that resolves issues of dividing the debt between roomates.

đŸŒŗ Environment – a nicer, type-safe way of working with environment variables in Swift.

đŸŒŗ Environment Welcome to Environment – a nicer, type-safe way of working with environment variables in Swift. Usage Access Environment Variables The

SwiftTypeReader - You can gather type definitions from Swift source code.

SwiftTypeReader - You can gather type definitions from Swift source code.

Type-based input validation.

Ensure Type-based input validation try EnsurePackageIsCool(wrappedValue: packages.ensure) Validators A Validator is a type that validates an input.

React Native utility library around image and video files for getting metadata like MIME type, timestamp, duration, and dimensions. Works on iOS and Android using Java and Obj-C, instead of Node 🚀.

Qeepsake React Native File Utils Extracts information from image and video files including MIME type, duration (video), dimensions, and timestamp. The

VaporDocC provides middleware for use with Vapor.

VaporDocC provides middleware for use with Vapor. To initialise the middleware pass in the path to your .doccarchive, e.g.:

Releases(0.1.0)
Owner
Miquido
Custom software development company
Miquido
API-Gateway/ Lambda-Function Structure

This was an app I meant to release on the Apple App Store, can't do that now so here's the code

S 2 Mar 16, 2022
Open-source implementation of Apple's Combine for processing values over time

CombineX įŽ€äŊ“中文 Open-source implementation of Apple's Combine for processing values over time. Though CombineX have implemented all the Combine interfac

Luo Xiu 1 Dec 30, 2021
Trigonometry - A small package to calculate values in an right angled triangle

Trigonometry - A small package to calculate values in an right angled triangle

null 2 Sep 12, 2022
RetroVisor helps you with inspecting UIViews in your unit tests.

RetroVisor RetroVisor helps you with inspecting UIViews in your unit tests. You do test views in unit tests, right? Right? Usually, I mark subview pro

Vid Tadel 2 Mar 29, 2022
Runtime Mobile Security (RMS) 📱đŸ”Ĩ - is a powerful web interface that helps you to manipulate Android and iOS Apps at Runtime

Runtime Mobile Security (RMS) ?? ?? by @mobilesecurity_ Runtime Mobile Security (RMS), powered by FRIDA, is a powerful web interface that helps you to

Mobile Security 2k Dec 29, 2022
Xcode Plugin helps you find missing methods in your class header, protocols, and super class, also makes fast inserting.

FastStub-Xcode Life is short, why waste it on meaningless typing? What is it? A code generating feature borrowed from Android Studio. FastStub automat

mrpeak 509 Jun 29, 2022
An Xcode Source Editor Extension that helps navigating to many places easier

XcodeWay ❤ī¸ Support my apps ❤ī¸ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut man

Khoa 543 Dec 1, 2022
A Simple way help you drop or drag your source (like UIImage) between different App.

A Simple way help you drop or drag your source (like UIImage) between different App.

逸éŖŽ 13 Nov 24, 2022
a playground app using `MultipeerConnectivity` to transfor data wirelessly between iOS / iPadOS

README An example app using MultipeerConnectivity to transfor data wirelessly between iOS / iPadOS. Both using Data and Stream to transfer data are su

null 3 Aug 6, 2022
Near Procedure Call between flutter and native.

npcx A new flutter plugin project. Getting Started This project is a starting point for a Flutter plug-in package, a specialized package that includes

null 0 Jun 17, 2022