Latest0.9.2
Homepagehttps://github.com/iamchiwon/CWUtils
LicenseMIT
Platformsios 9.0
DependenciesRxSwift, RxCocoa, RxOptional, SnapKit
Authors

Version
License
Platform

Installation

CWUtils is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'CWUtils'

Dependancies

  • RxSwift
  • RxCocoa
  • RxOptional
  • SnapKit

Sample Code

Utilities

Logs

DLog("log for debug build only")
ELog("error log for all build")

Device

runOnSimulatorOnly {
    print("running on simulator")
}
runOnDeviceOnly {
    print("running on device")
}

Version Check

let currentVersion: String = currentApplicationVersion()
let needUpdate: Bool = isUpdateAvailable()

Validataion

let isEmail = "[email protected]".isValid(withType: .email)
let isEmail2 = "[email protected]".isValid(withRegEx: "[A-Z0-9a-z._%+-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,6}")

Extensions

Strings

let url = "www.apple.com".url()
let base64 = "hello world".base64()
let trimmed = "   hello world   n n    ".trim()
let localized = "Hello World".localized()

Date

let serverDateParser = Date.fromFormat("yyyy-MM-dd HH:mm:ss")
let date = serverDateParser("2018-02-17 17:00:00")

Array

struct Data : Equatable {}
var array: [Data]
//--------
let data = Data()
let exists: Bool = array.exists(data)
let index: Int = array.indexOf(data)
let array2 = array.removed(data)
array.remove(item: data) //mutating
let shuffled = array.shuffled()

Codable

struct Data : Codable {}
//--------
let data = Data()
let dictionary: [String:Any] = data.dictionary()
let jsonString: String = data.json()
let jsonString2: String = dictionary.json()
let data2: Data = dictionary.decode()

UI

UIColor

let red = UIColor(red:255, green:0, blue:0)
let blue = UIColor(0x00FF00)
let green = UIColor("#0000FF")

subview

//view with tag
view.label(100)?.text = "Hello World"
//image with tag
view.imageView(100)?image = nil

popup

if needUpdate {
    popupOkCancel(on: self, title: "업데이트", message: "업데이트가 필요합니다.", onOk: {
        let urlString = "itms-apps://itunes.apple.com/app/id0000000000"
        UIApplication.shared.openURL(URL(string: urlString)!)
    })
} else {
    popupOK(on: self, title: "업데이트", message: "최신버전입니다.")
}

Image Resize

let original = UIImage(named: "big_image")
let resized = original?.resized(maxSize: CGSize(width: 100, height: 100))
let resizedForScreen = original?.resizedToScreen()

View Createor (with SnapKit)

let rect = createView(UIView(), parent: self.view, setting: { v in
            v.backgroundColor = .red
        }, constraint: { m in
            m.top.left.equalToSuperview()
            m.width.height.equalTo(100)
        })

RxSwift

GestureRecognizer

view.addTapGestureRecognizer()
    .subscribe(onNext: { (tapGusture : UITapGestureRecognizer) in
    })

view.addSwipeGestureRecognizer()
    .subscribe(onNext: { (tapGusture : UISwipeGestureRecognizer) in
    })

Button

//prevent double touched
view.button(100)?.whenTouchUpInside(thro)
    .subscribe(onNext: { button in
    })

Keyboard Notification

whenKeyboardShowNotification()
    .subscribe(onNext: { (keyboardHeight: CGFloat, duration: TimeInterval) in
    })
    .disposed(by: disposeBag)

whenKeyboardHideNotification()
    .subscribe(onNext: { (duration: TimeInterval) in
    })
    .disposed(by: disposeBag)

ScrollView

collectionView.needsMore()
    .filter { !self.isLoading }
    .subscribe(onNext: { self.loadMore() })
    .disposed(by: disposeBag)

Image Picker

pickImageFromAlbum(on: self, withEdit: true)
    .subscribe(onNext: {  self.imageView.image = $0 })

History

  • 0.9.2 : Support Swift 4.2

Author

iamchiwon, [email protected]

License

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

Latest podspec

{
    "name": "CWUtils",
    "version": "0.9.2",
    "summary": "iOS uc5b4ud50cub9acucf00uc774uc158 uac1cubc1cuc6a9 uc720ud2f8ub9acud2f0 ubaa8uc74c",
    "description": "RxSwift ub97c uae30ubc18uc73cub85c ud558uace0 uc788uc74c. (Dependancy : RxSwift, RxCocoa, RxOptional)",
    "homepage": "https://github.com/iamchiwon/CWUtils",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "iamchiwon": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/iamchiwon/CWUtils.git",
        "tag": "0.9.2"
    },
    "source_files": "CWUtils/Classes/**/*",
    "dependencies": {
        "RxSwift": [],
        "RxCocoa": [],
        "RxOptional": [],
        "SnapKit": []
    }
}

Pin It on Pinterest

Share This