Great Swift String Pluralize Extension

Related tags

Text Pluralize.swift
Overview

Pluralize.swift

Great Swift String Pluralize Extension

  • case-insensitive
  • tons of rules for irregular nouns (plural form)
  • supports uncountable nouns
  • allows dynamic addition of rules

Read this post for more information.

Basic usage

import Pluralize

"Person".pluralize()
// People

"Wolf".pluralize(count: 1)
// Wolf

"Person".pluralize(with: "Persons")
// Persons

Examples

Irregular Nouns Always Singular in Form
"Amnesty".pluralize() Amnesties "Coffee".pluralize() Coffee
"Dwarf".pluralize() Dwarves "Compassion".pluralize() Compassion
"Hypothesis".pluralize() Hypotheses "Deer".pluralize() Deer
"Oasis".pluralize() Oases "Food".pluralize() Food
"Scarf".pluralize() Scarves "Happiness".pluralize() Happiness
"Tableau".pluralize() Tableaux "Species".pluralize() Species
"Vertebra".pluralize() Vertebrae "Stuff".pluralize() Stuff

Adding Custom Rules: Singular = Plural

"Shrimp".pluralize()
// Shrimps

Pluralize.unchanging("shrimp")

"Shrimp".pluralize()
// Shrimp

Adding Custom Rules: Uncountable

"Water".pluralize()
// Waters

Pluralize.uncountable("water")
"Water".pluralize()
// Water

Adding Custom Rules: New Regex Rule

"Person".pluralize()
// People

Pluralize.rule("(p)erson$", with: "$1ersons")
"Person".pluralize()
// Persons
"Spokesperson".pluralize()
// Spokespersons

Example Regex Rules:

Pluralize.rule("(criteri|phenomen)on$", with:"$1a")
Pluralize.rule("(potat|tomat|volcan)o$", with:"$1oes")
Pluralize.rule("^(|wo|work)man$", with: "$1men")
Pluralize.rule("(f)oot$", with: "$1eet")
Pluralize.rule("lf$", with: "$1lves")
Pluralize.rule("(t)ooth$", with: "$1eeth")
Pluralize.rule("(g)oose$", with: "$1eese")
Pluralize.rule("^(c)hild$", with: "$1hildren")
Pluralize.rule("^(o)x$", with: "$1xen")

Adding Custom Rules: Whole Words

Pluralize.rule("were", with: "was")

Installation

Cocoapods

pod 'Pluralize.swift'

in code then

import Pluralize_swift

Manual Installation

  1. git clone https://github.com/joshualat/Pluralize.swift.git inside your project folder
  2. Drag the Pluralize.xcodeproj file into the file navigator of your project.
  3. Ensure that the deployment target of Pluralize.framework matches that of the application target.
  4. In your target’s Build Phases, add Pluralize to the Target Dependencies build phase.
  5. Add the appropriate Pluralize.framework product to the Link Binary With Libraries build phase.
  6. Add the same Pluralize.framework to a Copy Files build phase with a Frameworks destination.

License

Copyright (c) 2014 Joshua Arvin Lat

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Bump version to 2.0

    Bump version to 2.0

    This bumps the version to 2.0, which supports Swift 3.

    After merging this PR, please create a 2.0 tag:

    cd Pluralize.swift/
    git checkout master
    git pull origin master
    git tag 2.0
    git push origin 2.0
    

    Then, send an update to CocoaPods, that way we can just run pod update Pluralize.swift and get all of the Swift 4 goodies:

    pod trunk push
    

    Thanks a lot!

    opened by jeffaburt 4
  • Add support for OS X

    Add support for OS X

    I'd like to use Pluralize.swift in a Mac app. It'd be nice if this library supported both OS X and iOS. I can take a swing at implementing this today.

    Seems like this is the cleanest solution: http://colemancda.github.io/programming/2015/02/11/universal-ios-osx-framework/

    opened by natan 1
  • Error with word ended with -y

    Error with word ended with -y

    I try the project with "City".pluralize() and "Amnesty".pluralize()

    Result : "Citys" and "Amnestys" Good result : "Cities" and "Amnesties"

    I think this rule is not good :

    rule("(r|l|b)y$", with:"$1ies")
    

    Thx,

    opened by lemonnm 1
  • Private init

    Private init

    I made the Pluralizer class initialiser private as there is no need to initialiser it outside the class and it prevents there to be more than an instance of the class.

    opened by Gtwatt1 0
  • Can I use it for swift 4?

    Can I use it for swift 4?

    Hi, I would like to use this for swift 4. I have included the Pluralize framework in my project. Changed the deployment target to 10.12 since it is my main project deployment project. git clone https://github.com/joshualat/Pluralize.swift.git inside your project folder I have done the steps: Drag the Pluralize.xcodeproj file into the file navigator of your project. Ensure that the deployment target of Pluralize.framework matches that of the application target. In your target’s Build Phases, add Pluralize to the Target Dependencies build phase. Add the appropriate Pluralize.framework product to the Link Binary With Libraries build phase. Add the same Pluralize.framework to a Copy Files build phase with a Frameworks destination.

    I have tried both import Pluralize_swift and import Pluralize. But it has showed me that the module is not found.

    Is this because I cannot use swift 4 for Pluralize framework you build?

    Thank you, Gemma

    opened by GemmaJing 2
  • CocoaPods not updated with Swift 3 updates

    CocoaPods not updated with Swift 3 updates

    I followed the instructions for installing Pluralize into my project, and when attempting to build, it appears the version pulled from CocoaPods is out of date. Is there a version I should explicitly specify in my podfile?

    opened by nickmeehan 1
Owner
Joshua Arvin Lat
Chief Technology Officer
Joshua Arvin Lat
A comprehensive, lightweight string extension for Swift

SwiftString SwiftString is a lightweight string extension for Swift. This library was motivated by having to search StackOverflow for common string op

Andrew Mayne 1.6k Dec 30, 2022
BonMot is a Swift attributed string library

BonMot (pronounced Bon Mo, French for good word) is a Swift attributed string library. It abstracts away the complexities of the iOS, macOS, tvOS, and

Rightpoint 3.4k Dec 30, 2022
Croc is a swift emoji string parsing library

Croc is a library for parsing emojis on iOS. It provides a simple and lightweight interface for detecting, generating, categorizing and managing emoji characters, making emoji-powered features an easy task for developers.

Joe Kalash 127 Nov 20, 2022
👩‍🎨 Elegant Attributed String composition in Swift sauce

Elegant Attributed String composition in Swift sauce SwiftRichString is a lightweight library which allows to create and manipulate attributed strings

Daniele Margutti 2.9k Jan 5, 2023
🌍⏩📄 Convert ISO8859 1-16 Encoded Text to String in Swift. Supports iOS, tvOS, watchOS and macOS.

ISO8859 Convert ISO8859 1-16 Encoded Text to String in Swift. Usage let encoding = ISO8859.part1 let string = String([...], iso8859Encoding: encoding)

Devran Cosmo Uenal 18 Jan 2, 2023
A Cross-Platform String and Regular Expression Library written in Swift.

Guitar ?? A Cross-Platform String and Regular Expression Library written in Swift. About This library seeks to add common string manipulation function

Arthur Ariel Sabintsev 659 Dec 27, 2022
Swift emoji string parsing library

Croc is a library for parsing emojis on iOS. It provides a simple and lightweight interface for detecting, generating, categorizing and managing emoji

Joe Kalash 125 Sep 27, 2021
More powerful label, attributed string builder and text parser.

DDText More powerful label, attributed string builder and text parser. DDLabel More powerful label than UILabel, using TextKit. It supports features b

Daniel 16 Nov 8, 2022
String (and more) validation for iOS

Swift Validators ?? String validation for iOS. Contents Installation Walkthrough Usage Available validators License ReactiveSwift + SwiftValidators Wa

George Kaimakas 241 Nov 13, 2022
Easy string decoration with styles

StyleDecorator Design string simply by linking attributes. Example Create Decorator with specific Style and link it at the end of needed string or wra

Dmytro Pylypenko 15 Nov 4, 2021
Easy Attributed String Creator

The main idea of this project is to have an online tool to be able to visually add formatting to a text and get back a swift and/or objective-c code t

Andres Canal 283 Dec 27, 2022
Fully open source text editor for iOS written in Swift.

Edhita Fully open source text editor for iOS written in Swift. http://edhita.bornneet.com/ What Edhita means? Edhita (Romaji) == エディタ (Katakana) == Ed

Tatsuya Tobioka 1.2k Jan 1, 2023
A simple and customizable Markdown Parser for Swift

MarkdownKit MarkdownKit is a customizable and extensible Markdown parser for iOS and macOS. It supports many of the standard Markdown elements through

Bruno Oliveira 687 Dec 18, 2022
Marky Mark is a parser written in Swift that converts markdown into native views.

Marky Mark is a parser written in Swift that converts markdown into native views. The way it looks it highly customizable and the supported markdown syntax is easy to extend.

M2mobi 287 Nov 29, 2022
Swift Parser Combinators

Parsey Swift Parser Combinator Framework In addition to simple combinators, Parsey supports source location/range tracking, backtracking prevention, a

Richard Wei 56 Jun 30, 2022
An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift.

PrediKit A Swift NSPredicate DSL for iOS & OS X inspired by SnapKit, lovingly written in Swift, and created by that weird dude at KrakenDev. If you're

Hector Matos 542 Sep 24, 2022
PySwiftyRegex - Easily deal with Regex in Swift in a Pythonic way

PySwiftyRegex Easily deal with Regex in Swift in a Pythonic way.

Ce Zheng 232 Oct 12, 2022
Regular expressions for swift

Regex Advanced regular expressions for Swift Goals Regex library was mainly introduced to fulfill the needs of Swift Express - web application server

Crossroad Labs 328 Nov 20, 2022