• Stars
    star
    4,045
  • Rank 10,748 (Top 0.3 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

โœจ Super sweet syntactic sugar for Swift initializers

Then

Swift CocoaPods Build Status

โœจ Super sweet syntactic sugar for Swift initializers.

At a Glance

Initialize UILabel then set its properties.

let label = UILabel().then {
  $0.textAlignment = .center
  $0.textColor = .black
  $0.text = "Hello, World!"
}

This is equivalent to:

let label: UILabel = {
  let label = UILabel()
  label.textAlignment = .center
  label.textColor = .black
  label.text = "Hello, World!"
  return label
}()

Tips and Tricks

  • You can use then() to all of NSObject subclasses.

    let queue = OperationQueue().then {
      $0.maxConcurrentOperationCount = 1
    }
  • Want to use with your own types? Just make extensions.

    extension MyType: Then {}
    
    let instance = MyType().then {
      $0.really = "awesome!"
    }
  • Use with() when copying the value types.

    let newFrame = oldFrame.with {
      $0.size.width = 200
      $0.size.height = 100
    }
    newFrame.width // 200
    newFrame.height // 100
  • Use do() to do something with less typing.

    UserDefaults.standard.do {
      $0.set("devxoul", forKey: "username")
      $0.set("[email protected]", forKey: "email")
      $0.synchronize()
    }

Real World Example

Here's an example usage in an UIViewController subclass.

final class MyViewController: UIViewController {

  let titleLabel = UILabel().then {
    $0.textColor = .black
    $0.textAlignment = .center
  }

  let tableView = UITableView().then {
    $0.backgroundColor = .clear
    $0.separatorStyle = .none
    $0.register(MyCell.self, forCellReuseIdentifier: "myCell")
  }

  override func viewDidLoad() {
    super.viewDidLoad()
    self.view.addSubview(self.titleLabel)
    self.view.addSubview(self.tableView)
  }

}

Installation

  • Using CocoaPods:

    pod 'Then'
  • Using Swift Package Manager:

    import PackageDescription
    
    let package = Package(
      name: "MyAwesomeApp",
      dependencies: [
        .Package(url: "https://github.com/devxoul/Then", majorVersion: 2),
      ]
    )

License

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

More Repositories

1

URLNavigator

โ›ต๏ธ Elegant URL Routing for Swift
Swift
3,219
star
2

Toaster

๐Ÿž Toast for Swift
Swift
1,668
star
3

UITextView-Placeholder

A missing placeholder for UITextView
Objective-C
1,458
star
4

RxTodo

iOS Todo Application using RxSwift and ReactorKit
Swift
1,291
star
5

SwiftyImage

๐ŸŽจ Generate image resources in Swift
Swift
1,075
star
6

SwiftUITodo

An example to-do list app using SwiftUI which is introduced in WWDC19
Swift
715
star
7

Umbrella

โ˜‚๏ธ Analytics abstraction layer for Swift
Swift
607
star
8

Drrrible

Dribbble for iOS using ReactorKit
Swift
514
star
9

Pure

Pure DI in Swift
Swift
366
star
10

CocoaSeeds

Git Submodule Alternative for Cocoa.
Ruby
341
star
11

RxViewController

RxSwift wrapper for UIViewController and NSViewController
Swift
331
star
12

SwipeBack

Enable iOS 7+ swipe-to-back when custom back button is set.
Objective-C
321
star
13

UICollectionViewFlexLayout

A drop-in replacement for UICollectionViewFlowLayout
Swift
296
star
14

MoyaSugar

๐Ÿฏ Syntactic sugar for Moya
Swift
191
star
15

Carte

๐Ÿด Open source license notice view generator for Swift
Ruby
189
star
16

graygram-ios

[40์‹œ๊ฐ„๋งŒ์— Swift๋กœ iOS ์•ฑ ๋งŒ๋“ค๊ธฐ] ํ‘๋ฐฑ ์‚ฌ์ง„ ์ „์šฉ ์†Œ์…œ ๋ฏธ๋””์–ด ์•ฑ
Swift
180
star
17

ReusableKit

Generic reusables for UICollectionView and UITableView
Swift
158
star
18

UINavigationItem-Margin

Margins for UINavigationItem
Objective-C
158
star
19

allkdic

์˜ฌใ…‹์‚ฌ์ „ - ๋งฅ์—์„œ ๋‹จ์ถ•ํ‚ค๋ฅผ ๋ˆ„๋ฅด๋ฉด ์˜์–ด์‚ฌ์ „์ด ๋™‡!!!!
Swift
128
star
20

SwiftyColor

๐ŸŽจ The most sexy way to use colors in Swift.
Swift
120
star
21

RxCodable

RxSwift wrapper for Codable
Swift
113
star
22

RxExpect

RxSwift testing framework
Swift
105
star
23

korail

๐Ÿš† An unofficial Korail API for Python.
Python
90
star
24

Stubber

A minimal method stub for Swift
Swift
86
star
25

Cleverbot

iOS Messaging Application using Cleverbot and ReactorKit
Swift
78
star
26

Blockchain

A blockchain simulator written in Swift
Swift
65
star
27

LetsGitHubSearch

Let'Swift 18 Workshop - Let's TDD
Swift
63
star
28

CancelBag

A DisposeBag for Combine
Swift
53
star
29

TouchAreaInsets

Expand UIView touch area just like a charm
Objective-C
50
star
30

UIViewController-NavigationBar

[Deprecated] UIViewController with its own navigation bar. It provides an availability for the smooth push/pop animations between view controllers which have different navigation bar styles.
Swift
50
star
31

ios-with-swift-in-40-hours

40์‹œ๊ฐ„๋งŒ์— Swift๋กœ iOS ์•ฑ ํ•˜๋‚˜๋ฅผ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค.
49
star
32

SectionReactor

A ReactorKit extension for managing table view and collection view sections with RxDataSources
Swift
45
star
33

Fallback

๐Ÿ’Š Syntactic sugar for Swift do-try-catch
Swift
42
star
34

SafeCollection

Safe Collection for Swift
Swift
42
star
35

AsyncBlockOperation

NSOperation subclass for async block.
Objective-C
41
star
36

CGFloatLiteral

CGFloat(10) becomes 10.f
Swift
35
star
37

Endpoint

๐Ÿš€ Elegant API Abstraction for Swift
Swift
35
star
38

RxJSON

RxSwift wrapper for JSON
Swift
33
star
39

ASCollectionFlexLayout

A custom collection layout that allows to use Texture layout specs in ASCollectionNode.
Swift
27
star
40

next-route-map

๐Ÿš Routes for Next.js
TypeScript
26
star
41

Date.swift

๐Ÿ“… A Swift Date Library
Swift
26
star
42

ImageEffects

Bring UIImageEffects (WWDC 2013) to UIImage category with handy interface.
Objective-C
25
star
43

Todobox

[40์‹œ๊ฐ„๋งŒ์— Swift๋กœ iOS ์•ฑ ๋งŒ๋“ค๊ธฐ] ํ•  ์ผ ๋ชฉ๋ก ๊ด€๋ฆฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜
Swift
24
star
44

RxReusable

Reusable cells and views for RxSwift
Swift
23
star
45

AlertReactor

A ReactorKit extension for UIAlertController
Swift
23
star
46

UIButton-BackgroundContentMode

A missing background content mode for UIButton.
Objective-C
22
star
47

sketch-export-sizes-generator

๐Ÿ’Ž A simple plugin for Sketch that generates export sizes of layers.
20
star
48

RxDelegateCells

[Don't use this] UITableView Cell Height and UICollectionView Cell Size for RxSwift
Swift
19
star
49

Immutable

Missing non-mutating functions in Swift
Swift
18
star
50

PureSwinject

Auto register Pure factories to Swinject
Swift
18
star
51

graygram-web

Python
16
star
52

daumpostcode

๋‹ค์Œ ์šฐํŽธ๋ฒˆํ˜ธ ์„œ๋น„์Šค๋ฅผ ๋ณ„๋„์˜ ํŒจํ‚ค์ง€ ์„ค์น˜ ์—†์ด๋„ ๋„ค์ดํ‹ฐ๋ธŒ ์•ฑ์—์„œ ์‰ฝ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
HTML
16
star
53

Swiftproj

A command-line tool for managing Xcode project with Swift Package Manager.
Ruby
15
star
54

Meal

[40์‹œ๊ฐ„๋งŒ์— Swift๋กœ iOS ์•ฑ ๋งŒ๋“ค๊ธฐ] ์ „๊ตญ ์ดˆ/์ค‘/๊ณ ๋“ฑํ•™๊ต ๊ธ‰์‹ ์กฐํšŒ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜
Swift
15
star
55

SwinjectSafeAuto

SwinjectSafeAuto allows to auto-register services to the container and verify the required services are properly registered.
Swift
14
star
56

FastLogin

2018 FAST CAMPUS DEV SEMINAR ์‹ค์Šต ์•ฑ
Swift
14
star
57

NSOperationQueue-CompletionBlock

Completion block for NSOperationQueue.
Objective-C
13
star
58

graphql-codegen-typescript-fixtures

A plugin for graphql-code-generator that generates TypeScript fixtures for testing.
TypeScript
12
star
59

Kodium

Better Korean typo for medium.com
JavaScript
11
star
60

Estimator

Planning Poker application that communicates over BLE (Bluetoothe Low Energy)
Swift
10
star
61

Slots

Dynamic contents management for Swift.
Swift
9
star
62

MapViewVisibleAnnotations

Displays which annotations are currently visible in the specific area.
Swift
9
star
63

jira-velocity-chart-completion-rate

Displays completion rate in JIRA velocity chart.
JavaScript
9
star
64

github-monospace-editor

GitHub Monospace Editor Userscript
JavaScript
9
star
65

flask-restdoc

Flask-Restdoc is a simple tool that generates RESTful API documentation automatically from python files.
Python
9
star
66

notion-badge

Embed App Store badge in Notion
HTML
9
star
67

SwinjectFactory

Experimental Swinject extension for factory injection.
Swift
8
star
68

if_

Swift if-else statement as an expression (Experimental)
Swift
8
star
69

flask-errorhandler

Error handlers for Flask blueprints.
Python
7
star
70

shlee322-fb-troll

์ƒํ˜์ด์˜ ํŽ˜๋ถ ๊ธ€๋งˆ๋‹ค ์ผํ•˜๋ผ๋Š” ๋Œ“๊ธ€์„ ๋‹ฌ์•„๋ณด์•„์š” ^์˜ค^
Python
7
star
71

adorable

M๊™ผฬˆaฬ†ฬŽkฬŠฬˆeฬŒฬˆ tฬฬˆeฬ‘ฬˆxฬ†ฬˆt๊™ผฬˆ aฬŠฬˆdฬŒฬˆoฬ„ฬˆrฬฬˆaฬ‘ฬˆbฬ†ฬˆl๊™ผฬˆeฬ†ฬŽ
HTML
7
star
72

ModelKit

[deprecated] Experimental Model framework for Swift
Swift
7
star
73

resume

My rรฉsumรฉ
Makefile
6
star
74

Playground

A playground for an ideal project
HCL
6
star
75

Bagel

GIF converter for Mac
Swift
5
star
76

RxGitHubSearch

An example GitHub search app for my lecture
Swift
5
star
77

xcode-project-template

Swift
5
star
78

staccato

Staccato ๋ชจ์ž„ ์†Œ๊ฐœ ํŽ˜์ด์ง€
Python
5
star
79

fbmarkdown

Chrome extension that enable markdown on facebook.
JavaScript
5
star
80

JLModel

JLModel allows you to manage models in very simple way.
Objective-C
5
star
81

blog

์–ธ์  ๊ฐ„ ์“ฐ๊ฒ ์ง€?
CSS
4
star
82

TypedKey

Statically-typed key for Swift.
Swift
4
star
83

devxoul.github.io

HTML
4
star
84

Hippo-iOS

Objective-C
4
star
85

naver-cafe-chat-notification

๋„ค์ด๋ฒ„ ์นดํŽ˜ ์ƒˆ ์ฑ„ํŒ… ๊ฐœ์ˆ˜๋ฅผ ๋ธŒ๋ผ์šฐ์ € ํƒ€์ดํ‹€๋กœ ์•Œ๋ ค์ฃผ๋Š” ์Šคํฌ๋ฆฝํŠธ.
JavaScript
4
star
86

fabric-verbose

Python
4
star
87

TistoryMarkdown

A Markdown plugin for Tistory.
4
star
88

4SharedDownloader

You can download files from 4shared.com without delay.
ActionScript
4
star
89

help-me-rx-tableview-cell-height

Help me!
Swift
3
star
90

macsafe

Keep your MacBook from thieves.
Python
3
star
91

NAR

Nginx Auto Reloader
JavaScript
2
star
92

Editag

The easiest way to edit id3 tag.
ActionScript
2
star
93

ImageCrawler

JavaScript
2
star
94

ovenbreak

Utils for ovenapp.io
Makefile
2
star
95

JLChromeTabController

A chrome-like tab bar for iOS.
Objective-C
2
star
96

Evermind

Evermind is a handy tool that makes it easy to mindmap your idea from your work, study, and everyday life.
ActionScript
2
star
97

JLUtils

Objective-C
1
star
98

FastcampusFrame

Swift
1
star
99

Sonaki

Objective-C
1
star
100

Calendar

Infinite-scrolling calendar example
Objective-C
1
star