Laconic 4.0

Laconic 4.0

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布上次发布2017年10月
SwiftSwift 版本3.0
SPM支持 SPM

Igor Matyushkin 维护。




Laconic

Laconic

Swift 中的简洁明了的表达

如何开始

  • Laconic 文件夹的内容复制到您的项目中。

或者

  • 使用 Laconic Cocoapod

要求

  • iOS 9.0 及以上版本
  • Xcode 8 及以上版本

注意:对于 Swift 2.x,使用 Laconic v1.9.3。对于 Swift 3.0,使用 Laconic v3.0

用法

平方根

/*
 * 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

相等性

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

let eightIsMoreOrEqualToHalf = 80.5            // true

let oneIsMoreOrEqualToSeven = 17               // false

let twentyFourIsLessOrEqualToNinety = 2490     // true

求和

/*
 * 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]

视图

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

以下是支持的视图操作运算符的完整列表

/*
 * 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-->

许可证

Laconic 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。