Latest 4.0
Homepage https://github.com/igormatyushkin014/Laconic
License MIT
Platforms ios 9.0
Authors

Laconic




Short and clear expressions in Swift.

How To Get Started

  • Copy content of Laconic folder to your project.

or

  • Use Laconic cocoapod

Requirements

  • iOS 9 and later
  • Xcode 9 and later

Usage

Square roots

/*
 * Square root of 2nd degree.
 */

let someNumber = 4
let squareRoot = √someNumber                  // 2

/*
 * Square root of 8th degree.
 */

let anotherSquareRoot = √√√65536              // 4

/*
 * Square root of 16th degree.
 */

let oneMoreSquareRoot = √√√√(124500 + 3500)   // 2.085454039791327

Equality

/*
 * You can use ≤ operator instead of <=, and ≥ instead of >=
 */

let eightIsMoreOrEqualToHalf = 8 ≥ 0.5            // true

let oneIsMoreOrEqualToSeven = 1 ≥ 7               // false

let twentyFourIsLessOrEqualToNinety = 24 ≤ 90     // true

Sum

/*
 * Example of sum of several numbers.
 */

let numbers = [
    8,
    241,
    382,
    90
]

let sumOfNumbers = ∑numbers            // 721

/*
 * Also, you can get sum of strings.
 */

let sumOfStrings = ∑["a", "b", "c"]    // abc

/*
 * If you use ∑ operator with array of UIView objects,
 * you will get another UIView,
 * which is a superview for those elements in array.
 * In other words, each view in array will be added to container as a subview
 * and finally the container will be returned as a result of operation.
 */

let view1 = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 20.0, height: 20.0))
view1.backgroundColor = .greenColor()

let view2 = UIView(frame: CGRect(x: 20.0, y: 0.0, width: 20.0, height: 20.0))
view2.backgroundColor = .blueColor()

let container = ∑[view1, view2]

Views

let view1 = UIView()
let label1 = UILabel()
let containerView = UIView() // Will be used as superview for view1

/*
 * Set {0, 0, 200, 200} frame for view1.
 */

view1 --> CGRect(x: 0, y: 0, width: 200, height: 200)

/*
 * Also, it's possible to set frame by this command.
 */

view1 --> (0, 0, 200, 200)

/*
 * Set green background color for view1.
 */

view1 --> .greenColor()

/*
 * Add view1 to containerView as a subview.
 */

view1 --> containerView

/*
 * All those operations can be done in one line of code.
 */

view1 --> (0, 0, 200, 200) --> .greenColor() --> containerView

/*
 * Assume we want to set container's background color to blue.
 */

view1 --> (0, 0, 200, 200) --> .greenColor() --> (containerView --> .blueColor())

/*
 * Set label's text to "Hello" and add this label to view1.
 */

label1 --> "Hello" --> view1.bounds --> view1

/*
 * Set label's text, font, text alignment, frame and finally add to view1.
 */

label1 --> "Hello" --> UIFont.systemFontOfSize(20.0) --> .Center --> view1.bounds --> view1

Here is the full list of supported operators for manipulating views:

/*
 * Set background color for UIView object.
 */

let view1 = UIView()
view1 --> .greenColor()

/*
 * Set frame for UIView object.
 */

view1 --> CGRect(x: 0, y: 0, width: 200, height: 200)

/*
 * Set frame for UIView object.
 */

view1 --> (0, 0, 200, 200)

/*
 * Set top left coordinate for UIView object.
 */

view1 --> CGPoint(x: 20, y: 20)

/*
 * Set size for UIView object.
 */

view1 --> CGSize(width: 200, height: 200)

/*
 * Add UIView object as subview to another UIView object.
 */

view1 --> containerView

/*
 * Set text for UILabel object.
 */

let label1 = UILabel()
label1 --> "Hello"

/*
 * Set attributed text for UILabel object.
 */

let textAttributes: [String : AnyObject] = [
    NSFontAttributeName: UIFont.systemFontOfSize(20.0),
    NSForegroundColorAttributeName: UIColor.blackColor(),
    NSKernAttributeName: 0.5
]

let attributedText = NSAttributedString(string: "Hello", attributes: textAttributes)

label1 --> attributedText

/*
 * Set font for UILabel object.
 */

label1 --> UIFont.systemFontOfSize(20.0)

/*
 * Set text alignment for UILabel object.
 */

label1 --> .Center

/*
 * Set text for UITextView object.
 */

let textView1 = UITextView()
textView1 --> "Hello"

/*
 * Set attributed text for UITextView object.
 */

textView1 --> attributedText

/*
 * Set font for UITextView object.
 */

textView1 --> UIFont.systemFontOfSize(20.0)

/*
 * Set text alignment for UITextView object.
 */

textView1 --> .Center

/*
 * Set title for UIButton object.
 */

let button1 = UIButton()
button1 --> "Hello"

/*
 * Set attributed title for UIButton object.
 */

button1 --> attributedText

/*
 * Set image to UIImageView object.
 */

let image = UIImage(named: "image_name")

let imageView1 = UIImageView()
imageView1 --> image

/*
 * Set title for UINavigationItem object.
 */

let navigationItem1 = UINavigationItem()
navigationItem1 --> "Hello"

/*
 * Remove view from superview.
 */

view1-->

License

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

Latest podspec

{
    "name": "Laconic",
    "version": "4.0",
    "summary": "Short and clear expressions in Swift.",
    "description": "This library brings short and clear expressions into your Swift code.",
    "homepage": "https://github.com/igormatyushkin014/Laconic",
    "screenshots": "https://github.com/igormatyushkin014/Laconic/raw/master/Logo/logo-1024-300.png",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Igor Matyushkin": "[email protected]"
    },
    "social_media_url": "https://twitter.com/imatyushkin1",
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/igormatyushkin014/Laconic.git",
        "tag": "4.0"
    },
    "source_files": [
        "Laconic",
        "Laconic/**/*"
    ],
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This