Swift's Sugar. Heavily inspired on Objc Sugar

Related tags

Utility Swift-Sugar
Overview

Note: Used as an exercise mainly, still you can make use of it of course

Inspiration

Swift Sugar is heavily inspired on ObjectiveSugar.

Documentation

Int extensions

3.times {
    println("Hello!")
}
// Hello!
// Hello!
// Hello!
3.timesWithIndex {
    index in println(index)
}
// 0
// 1
// 2
3.upTo(5) {
    index in println(index)
}
// 3
// 4
5.downTo(0) {
    index in println(index)
}
// 5
// 4
// 3
// 2
// 1

Array functions

[1,2,3,4].initial(3)
// [1,2,3]
[1,2,3,4].initial()
// [1]
[1,2,3,4].drop {$0 % 2 ==0}
// [2,4]
[1,2,3,4].remove(2)
// [3,4]
[1,2,3,4].minimum()
// 1
[1,2,3,4].maximum()
// 4
[1,2,3,4,1].numberTimesRepeated(1)
// 2

String functions

"Swift programming".length
// 17
"Swift programming"[1]
// w
"Swift programming"[-4]
// m
String.join(["S","w","i"])
//Swi
String.join("S","w","i","f","t")
//Swift
"Swift programming".split()
//["Swift", "programming"]
"Swift programming".split(delimiter:"r")
//["Swift p", "og", "amming"]
"Swift programming".indexOfString("mm")
// 12
"Swift programming".toCharacterArray()
//["S","w","i","f","t"," ","p","r","o","g","r","a","m","m","i","n","g"]
"Swift programming".reverse()
//gnimmargorp tfiwS

Swift Sugar (Global functions)

let x : [(Int,Int)] = zip([1,2,3,4,5], [1,2,3])
// [(1,1),(2,2),(3,3)]
You might also like...
A μframework of extensions for SequenceType in Swift 2.0, inspired by Python's itertools, Haskell's standard library, and other things.

SwiftSequence Full reference here. (If you're looking for data structures in Swift, those have been moved to here) SwiftSequence is a lightweight fram

A result builder that build HTML parser and transform HTML elements to strongly-typed result, inspired by RegexBuilder.

HTMLParserBuilder A result builder that build HTML parser and transform HTML elements to strongly-typed result, inspired by RegexBuilder. Note: Captur

CCCryptor (AES encryption) wrappers for iOS and Mac in Swift. -- For ObjC, see RNCryptor/RNCryptor-objc

RNCryptor Cross-language AES Encryptor/Decryptor data format. The primary targets are Swift and Objective-C, but implementations are available in C, C

CCCryptor (AES encryption) wrappers for iOS and Mac in Swift. -- For ObjC, see RNCryptor/RNCryptor-objc

RNCryptor Cross-language AES Encryptor/Decryptor data format. The primary targets are Swift and Objective-C, but implementations are available in C, C

This Control is a beautiful time-of-day picker heavily inspired by the iOS 10
This Control is a beautiful time-of-day picker heavily inspired by the iOS 10 "Bedtime" timer.

#10Clock Dark and Mysterious 🕶 Light Colors 🌻 Usage The control itsself is TenClock. Add that to your view hierarchy, and constrain it to be square

Sonic language: Heavily inspired by Swift, but compiles to C so you can use it anywhere.
Sonic language: Heavily inspired by Swift, but compiles to C so you can use it anywhere.

Sonic Sonic programming language: Heavily inspired by Swift, but compiles to C so you can use it anywhere. Brought to you by Chris Hulbert and Andres

Kotlin Multiplatform sample with SwiftUI and Compose (Desktop and Android) clients. Heavily inspired by Wordle game.
Kotlin Multiplatform sample with SwiftUI and Compose (Desktop and Android) clients. Heavily inspired by Wordle game.

WordMasterKMP Kotlin Multiplatform sample heavily inspired by Wordle game and also Word Master and wordle-solver samples. The main game logic/state is

Punctual - Swift dates, more fun. Heavily inspired by ObjectiveSugar

Punctual Swift dates, more fun. Heavily inspired by ObjectiveSugar Installation Punctual is available through the Swift Package Manager! Just add this

Booky heavily-commented demo app built to explore Apple's new 'App Intents' framework introduced in iOS 16
Booky heavily-commented demo app built to explore Apple's new 'App Intents' framework introduced in iOS 16

Booky Demo App ℹ️ ABOUT Booky is a work-in-progress, heavily-commented demo app built to explore Apple's new 'App Intents' framework introduced in iOS

Promises for Swift & ObjC.
Promises for Swift & ObjC.

Promises simplify asynchronous programming, freeing you up to focus on the more important things. They are easy to learn, easy to master and result in

SuperVideoPlayer is video player in Objc.

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

Shows the issue with swift using an ObjC class which has a property from a swift package.

SwiftObjCSwiftTest Shows the issue with swift using an ObjC class which has a property from a swift package. The Swift class (created as @objc derived

The most power-efficient and lightweight iOS location manager for Swift and ObjC
The most power-efficient and lightweight iOS location manager for Swift and ObjC

IngeoSDK for iOS Overview IngeoSDK is a power-efficient location manager for iOS (Swift and Objective-C), which extends and improves CoreLocation. It

Google Material Design Icons for Swift and ObjC project
Google Material Design Icons for Swift and ObjC project

GoogleMaterialIconFont Google Material Design Icons for Swift and ObjC project This library is inspired by FontAwesome.swift Both Swift and Objctive-C

Extensions which helps to convert objc-style target/action to swifty closures

ActionClosurable Usage ActionClosurable extends UIControl, UIButton, UIRefreshControl, UIGestureRecognizer and UIBarButtonItem. It helps writing swift

just some bad (but working) objc code

resistors A small app to work with resistor color codes. Disclamer This is my first UIKit and first ObjC application, the code and storyboard quality

Inject-Dylib - ObjC Code to Programmatically Perform Dylib Injection
Inject-Dylib - ObjC Code to Programmatically Perform Dylib Injection

Inject-Dylib ObjC Code to Programmatically Perform Dylib Injection. Code leveraged from Wojciech Regula's FirefoxStealer project (https://github.com/r

RavynOS File manager built in Cocoa/Appkit and ObjC

Filer A file manager and re-implementation of macOS's Finder. A key component of ravynOS, Filer is the first application you see after you start ravyn

AudioPlayer is syntax and feature sugar over AVPlayer. It plays your audio files (local & remote).

AudioPlayer AudioPlayer is a wrapper around AVPlayer. It also offers cool features such as: Quality control based on number of interruption (buffering

Comments
  • remove min and max function.

    remove min and max function.

    Use standard minElement and maxElement functions

    If I try to use maximum with object that isn't Comparable it will crash at runtime. There is no type checking var maximum : Int = [A(), A()].maximum() - Crash var minimum : Int = minElement([A(), A()]) - compile error var minimum : Int = minElement([1,2,3,4,5] - work perfect

    I was trying to wrap minElement inside minimum. I failed because arrays don't have to store Comparable elements. I suggest to got for standard minElement and manElement

    opened by kostiakoval 4
  • Zip function

    Zip function

    I wanted to implement zip function But i'm not sure if Tuples are designed to be used this way in Swift as in Haskell.

    http://stackoverflow.com/questions/24487519/how-to-elegantly-compare-tuples-in-swift/24495112#24495112

    Tuples are useful for temporary groups of related values. They are not suited to the creation of complex data structures. If your data structure is likely to persist beyond a temporary scope, model it as a class or structure, rather than as a tuple. For more information, see Classes and Structures.

    What do you think ?

    opened by kostiakoval 4
  • Feature/defaultable and zip

    Feature/defaultable and zip

    1. I liked your zip function. I've implemented it as in Haskel

    2. I needed a way to created a default values for Generics. I found a solution to provide a Defaultable protocol and implement it

    looking forward to see it you like it :)

    opened by kostiakoval 1
  • Add tests and fix array remove method

    Add tests and fix array remove method

    Array remove method [1,2,3,4].remove(2) - result [2,4] after removing first item, array is shifted and indexes are changes. [1,2,3,4].removeAtIndex(0) - [2,3,4] [2,3,4].removeAtIndex(1) - [2,4] I've found better implementation.

    opened by kostiakoval 1
Owner
Rui Peres
Head of Engineering @ Vital 🛠 | Ultra Trail Runner 🏃‍♂️🏔 "Technology as a means to an end 🚀"
Rui Peres
📦 KeyPath dynamicMemberLookup based syntax sugar for Swift.

DuctTape ?? KeyPath dynamicMemberLookup based syntax sugar for Swift. let label: UILabel = UILabel().ductTape .numberOfLines(0) .textColor(.re

Taiki Suzuki 171 Nov 4, 2022
Sugar is a sweetener for your Cocoa implementations.

Sugar is a sweetener for your Cocoa implementations. Table of Contents iOS Application Screen Simulator Keyboard Observer iOS Extensions UIView

HyperRedink 1.1k Dec 29, 2022
✨ Super sweet syntactic sugar for Swift initializers

Then ✨ Super sweet syntactic sugar for Swift initializers. At a Glance Initialize UILabel then set its properties. let label = UILabel().then { $0.t

Suyeol Jeon 4k Jan 4, 2023
SharkUtils is a collection of Swift extensions, handy methods and syntactical sugar that we use within our iOS projects at Gymshark.

SharkUtils is a collection of Swift extensions, handy methods and syntactical sugar that we use within our iOS projects at Gymshark.

Gymshark 1 Jul 6, 2021
🍯 Syntactic sugar for Moya

MoyaSugar Syntactic sugar for Moya. Why? Moya is an elegant network abstraction layer which abstracts API endpoints gracefully with enum. However, it

Suyeol Jeon 186 Jan 6, 2023
Synatax sugar for Measurement of Foundation.

WrappedMeasurement 2022 © Weizhong Yang a.k.a zonble Syntax sugar for NSMeasurement of Foundation. NSMeasurement and NSUnit compose a great tool to le

Weizhong Yang a.k.a zonble 8 Jan 25, 2022
HumanMeasurementSwift - Synatax sugar for Measurement of Foundation

HumanMeasurement 2022 © Weizhong Yang a.k.a zonble Syntax sugar for NSMeasuremen

Weizhong Yang a.k.a zonble 8 Jan 25, 2022
And - Syntactic sugar for Swift initializers

And Syntactic sugar for Swift initializers Usage let label = UILabel().and { $0

donggyu 4 Jun 10, 2022
Swiftbot on slack. Inspired by kishikawakatsumi/swift-compiler-discord-bot

Swiftbot Swiftbot on slack. Inspired by kishikawakatsumi/swift-compiler-discord-bot Usage $ swiftbot --token xoxb-xxxxxxxxxxxx-xxxxxxxxxxxx-xxxxxxxxxx

noppefoxwolf 55 Jan 8, 2022
Swift Parser Combinator library inspired by NimbleParsec for Elixir.

SimpleParsec Simple parser combinator library for Swift inspired by NimbleParsec for Elixir. Each function in the library creates a Parser which can b

null 0 Dec 27, 2021