diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..36cec54 --- /dev/null +++ b/LICENCE @@ -0,0 +1,19 @@ +Copyright (c) 2018 tokijh + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Podfile b/Podfile new file mode 100644 index 0000000..ed8c745 --- /dev/null +++ b/Podfile @@ -0,0 +1,14 @@ +# Uncomment the next line to define a global platform for your project +# platform :ios, '9.0' + +target 'RxSwiftExtensions' do + # Comment the next line if you're not using Swift and don't want to use dynamic frameworks + use_frameworks! + + # Pods for RxSwiftExtensions + pod 'RxSwift', '~> 4.0' + pod 'RxCocoa', '~> 4.0' + pod 'RxOptional', '~> 3.5' + pod 'RxSwiftDo', '~> 1.1' + +end diff --git a/Podfile.lock b/Podfile.lock new file mode 100644 index 0000000..916a99e --- /dev/null +++ b/Podfile.lock @@ -0,0 +1,32 @@ +PODS: + - RxCocoa (4.2.0): + - RxSwift (~> 4.0) + - RxOptional (3.5.0): + - RxCocoa (~> 4.0) + - RxSwift (~> 4.0) + - RxSwift (4.2.0) + - RxSwiftDo (1.1): + - RxSwift (>= 4.0.0) + +DEPENDENCIES: + - RxCocoa (~> 4.0) + - RxOptional (~> 3.5) + - RxSwift (~> 4.0) + - RxSwiftDo (~> 1.1) + +SPEC REPOS: + https://github.com/cocoapods/specs.git: + - RxCocoa + - RxOptional + - RxSwift + - RxSwiftDo + +SPEC CHECKSUMS: + RxCocoa: 0b54909c902e1e581212a03e690bbd94032d8baa + RxOptional: bd32ff8ca9df4177683d56ffeb618a9d4d5d5cad + RxSwift: 99e10317ddfcc7fbe01356aafd118fde4a0be104 + RxSwiftDo: d51f6cf99b6e4f8c00534cf99c44007d7361158d + +PODFILE CHECKSUM: 0282ece30a6498815b1454b022eb4e7987987e51 + +COCOAPODS: 1.5.2 diff --git a/README.md b/README.md new file mode 100644 index 0000000..53d1607 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# RxSwiftExtensions + +[![Swift 4.2](https://img.shields.io/badge/swift-4.2-orange.svg?style=flat)](https://swift.org) + +Frequently used extensoins in RxSwift + +## Functions +- Swift + - KVO + - [x] `observe(keyPath: KeyPath)` + - [x] `observeWeakly(keyPath: KeyPath)` +- UIKit + - UIView + - [x] `bounds: Observable` + - [x] `center: Observable` + - UILabel + - [x] `textColor: Observable` + - UITextView + - [x] `textColor: Observable` + - UIScrollView + - [x] `contentSize: Observable` + - [x] `scrollableVertical: Observable` + - [x] `scrollableHorizontal: Observable` + - UITableView + - [x] `register(cell: UITableViewCell.self)` + - [x] `register(nibCell: UITableViewCell.self)` + - [x] `register(cell: UITableViewHeaderFooterView.self)` + - [x] `register(nibCell: UITableViewHeaderFooterView.self)` + - [x] `dequeue(UITableViewCell.self, indexPath: IndexPath)` + - [x] `dequeue(UITableViewHeaderFooterView.self, indexPath: IndexPath)` + - UITableViewCell + - [x] `Identifier: String` + - UITableViewHeaderFooterView + - [x] `Identifier: String` + - UICollectionView + - [x] `register(cell: UICollectionViewCell.self)` + - [x] `register(nibCell: UICollectionViewCell.self)` + - [x] `register(cell: UICollectionReusableView.self, forSupplementaryViewOfKind kind: String)` + - [x] `register(nibCell: UICollectionReusableView.self, forSupplementaryViewOfKind kind: String)` + - [x] `dequeue(UICollectionViewCell.self, for indexPath: IndexPath)` + - [x] `dequeue(UICollectionViewCell.self, ofKind kind: String, for indexPath: IndexPath)` + - UICollectionReusableView + - [x] `Identifier: String` + +## Author +[tokijh](https://github.com/tokijh) + +## License +RxSwiftExtensions is available under the MIT License See the [LICENSE](LICENSE) file for more info. + diff --git a/RxSwiftExtensions.xcodeproj/project.pbxproj b/RxSwiftExtensions.xcodeproj/project.pbxproj index d437e68..ed08678 100644 --- a/RxSwiftExtensions.xcodeproj/project.pbxproj +++ b/RxSwiftExtensions.xcodeproj/project.pbxproj @@ -7,13 +7,41 @@ objects = { /* Begin PBXBuildFile section */ + 9D51BCE16115BA46A8CE054B /* Pods_RxSwiftExtensions.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2F85474B07AB3A7EF690DA26 /* Pods_RxSwiftExtensions.framework */; }; CDB5A7172122DD6A001DB39B /* RxSwiftExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = CDB5A7152122DD6A001DB39B /* RxSwiftExtensions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + CDB5A7332122DDD4001DB39B /* KVO.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB5A71F2122DDD4001DB39B /* KVO.swift */; }; + CDB5A7342122DDD4001DB39B /* UIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB5A7232122DDD4001DB39B /* UIView.swift */; }; + CDB5A7352122DDD4001DB39B /* UIScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB5A7252122DDD4001DB39B /* UIScrollView.swift */; }; + CDB5A7362122DDD4001DB39B /* UILabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB5A7272122DDD4001DB39B /* UILabel.swift */; }; + CDB5A7372122DDD4001DB39B /* UITextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB5A7292122DDD4001DB39B /* UITextView.swift */; }; + CDB5A7382122DDD4001DB39B /* CollectionViewCellType.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB5A72B2122DDD4001DB39B /* CollectionViewCellType.swift */; }; + CDB5A7392122DDD4001DB39B /* UICollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB5A72C2122DDD4001DB39B /* UICollectionView.swift */; }; + CDB5A73A2122DDD4001DB39B /* UICollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB5A72D2122DDD4001DB39B /* UICollectionReusableView.swift */; }; + CDB5A73B2122DDD4001DB39B /* UITableViewHeaderFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB5A72F2122DDD4001DB39B /* UITableViewHeaderFooterView.swift */; }; + CDB5A73C2122DDD4001DB39B /* UITableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB5A7302122DDD4001DB39B /* UITableView.swift */; }; + CDB5A73D2122DDD4001DB39B /* UITableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB5A7312122DDD4001DB39B /* UITableViewCell.swift */; }; + CDB5A73E2122DDD4001DB39B /* TableViewCellType.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB5A7322122DDD4001DB39B /* TableViewCellType.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 2F85474B07AB3A7EF690DA26 /* Pods_RxSwiftExtensions.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RxSwiftExtensions.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 52DEE5AAECDF48D200F246BA /* Pods-RxSwiftExtensions.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxSwiftExtensions.release.xcconfig"; path = "Pods/Target Support Files/Pods-RxSwiftExtensions/Pods-RxSwiftExtensions.release.xcconfig"; sourceTree = ""; }; + 574C6916EBC97E1CA06977B3 /* Pods-RxSwiftExtensions.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxSwiftExtensions.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RxSwiftExtensions/Pods-RxSwiftExtensions.debug.xcconfig"; sourceTree = ""; }; CDB5A7122122DD6A001DB39B /* RxSwiftExtensions.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxSwiftExtensions.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CDB5A7152122DD6A001DB39B /* RxSwiftExtensions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RxSwiftExtensions.h; sourceTree = ""; }; CDB5A7162122DD6A001DB39B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + CDB5A71F2122DDD4001DB39B /* KVO.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KVO.swift; sourceTree = ""; }; + CDB5A7232122DDD4001DB39B /* UIView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIView.swift; sourceTree = ""; }; + CDB5A7252122DDD4001DB39B /* UIScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIScrollView.swift; sourceTree = ""; }; + CDB5A7272122DDD4001DB39B /* UILabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UILabel.swift; sourceTree = ""; }; + CDB5A7292122DDD4001DB39B /* UITextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextView.swift; sourceTree = ""; }; + CDB5A72B2122DDD4001DB39B /* CollectionViewCellType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewCellType.swift; sourceTree = ""; }; + CDB5A72C2122DDD4001DB39B /* UICollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UICollectionView.swift; sourceTree = ""; }; + CDB5A72D2122DDD4001DB39B /* UICollectionReusableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UICollectionReusableView.swift; sourceTree = ""; }; + CDB5A72F2122DDD4001DB39B /* UITableViewHeaderFooterView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITableViewHeaderFooterView.swift; sourceTree = ""; }; + CDB5A7302122DDD4001DB39B /* UITableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITableView.swift; sourceTree = ""; }; + CDB5A7312122DDD4001DB39B /* UITableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITableViewCell.swift; sourceTree = ""; }; + CDB5A7322122DDD4001DB39B /* TableViewCellType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewCellType.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -21,17 +49,37 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 9D51BCE16115BA46A8CE054B /* Pods_RxSwiftExtensions.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 374C07B007F1FFA01F593FFE /* Frameworks */ = { + isa = PBXGroup; + children = ( + 2F85474B07AB3A7EF690DA26 /* Pods_RxSwiftExtensions.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + BB81239F23571EC335CB9DF9 /* Pods */ = { + isa = PBXGroup; + children = ( + 574C6916EBC97E1CA06977B3 /* Pods-RxSwiftExtensions.debug.xcconfig */, + 52DEE5AAECDF48D200F246BA /* Pods-RxSwiftExtensions.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; CDB5A7082122DD6A001DB39B = { isa = PBXGroup; children = ( CDB5A7142122DD6A001DB39B /* RxSwiftExtensions */, CDB5A7132122DD6A001DB39B /* Products */, + BB81239F23571EC335CB9DF9 /* Pods */, + 374C07B007F1FFA01F593FFE /* Frameworks */, ); sourceTree = ""; }; @@ -48,10 +96,94 @@ children = ( CDB5A7152122DD6A001DB39B /* RxSwiftExtensions.h */, CDB5A7162122DD6A001DB39B /* Info.plist */, + CDB5A71D2122DDD4001DB39B /* Swift */, + CDB5A7212122DDD4001DB39B /* UIKit */, ); path = RxSwiftExtensions; sourceTree = ""; }; + CDB5A71D2122DDD4001DB39B /* Swift */ = { + isa = PBXGroup; + children = ( + CDB5A71E2122DDD4001DB39B /* KVO */, + ); + path = Swift; + sourceTree = ""; + }; + CDB5A71E2122DDD4001DB39B /* KVO */ = { + isa = PBXGroup; + children = ( + CDB5A71F2122DDD4001DB39B /* KVO.swift */, + ); + path = KVO; + sourceTree = ""; + }; + CDB5A7212122DDD4001DB39B /* UIKit */ = { + isa = PBXGroup; + children = ( + CDB5A7222122DDD4001DB39B /* UIView */, + ); + path = UIKit; + sourceTree = ""; + }; + CDB5A7222122DDD4001DB39B /* UIView */ = { + isa = PBXGroup; + children = ( + CDB5A7232122DDD4001DB39B /* UIView.swift */, + CDB5A7242122DDD4001DB39B /* UIScrollView */, + CDB5A7262122DDD4001DB39B /* UILabel */, + CDB5A7282122DDD4001DB39B /* UITextView */, + CDB5A72A2122DDD4001DB39B /* UICollectionView */, + CDB5A72E2122DDD4001DB39B /* UITableView */, + ); + path = UIView; + sourceTree = ""; + }; + CDB5A7242122DDD4001DB39B /* UIScrollView */ = { + isa = PBXGroup; + children = ( + CDB5A7252122DDD4001DB39B /* UIScrollView.swift */, + ); + path = UIScrollView; + sourceTree = ""; + }; + CDB5A7262122DDD4001DB39B /* UILabel */ = { + isa = PBXGroup; + children = ( + CDB5A7272122DDD4001DB39B /* UILabel.swift */, + ); + path = UILabel; + sourceTree = ""; + }; + CDB5A7282122DDD4001DB39B /* UITextView */ = { + isa = PBXGroup; + children = ( + CDB5A7292122DDD4001DB39B /* UITextView.swift */, + ); + path = UITextView; + sourceTree = ""; + }; + CDB5A72A2122DDD4001DB39B /* UICollectionView */ = { + isa = PBXGroup; + children = ( + CDB5A72B2122DDD4001DB39B /* CollectionViewCellType.swift */, + CDB5A72C2122DDD4001DB39B /* UICollectionView.swift */, + CDB5A72D2122DDD4001DB39B /* UICollectionReusableView.swift */, + ); + path = UICollectionView; + sourceTree = ""; + }; + CDB5A72E2122DDD4001DB39B /* UITableView */ = { + isa = PBXGroup; + children = ( + CDB5A72F2122DDD4001DB39B /* UITableViewHeaderFooterView.swift */, + CDB5A7302122DDD4001DB39B /* UITableView.swift */, + CDB5A7312122DDD4001DB39B /* UITableViewCell.swift */, + CDB5A7322122DDD4001DB39B /* TableViewCellType.swift */, + ); + path = UITableView; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -70,6 +202,7 @@ isa = PBXNativeTarget; buildConfigurationList = CDB5A71A2122DD6A001DB39B /* Build configuration list for PBXNativeTarget "RxSwiftExtensions" */; buildPhases = ( + 71414AECE6B2AB14D31998A8 /* [CP] Check Pods Manifest.lock */, CDB5A70D2122DD6A001DB39B /* Sources */, CDB5A70E2122DD6A001DB39B /* Frameworks */, CDB5A70F2122DD6A001DB39B /* Headers */, @@ -125,11 +258,44 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 71414AECE6B2AB14D31998A8 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-RxSwiftExtensions-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ CDB5A70D2122DD6A001DB39B /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CDB5A7352122DDD4001DB39B /* UIScrollView.swift in Sources */, + CDB5A73B2122DDD4001DB39B /* UITableViewHeaderFooterView.swift in Sources */, + CDB5A73A2122DDD4001DB39B /* UICollectionReusableView.swift in Sources */, + CDB5A7342122DDD4001DB39B /* UIView.swift in Sources */, + CDB5A7392122DDD4001DB39B /* UICollectionView.swift in Sources */, + CDB5A73D2122DDD4001DB39B /* UITableViewCell.swift in Sources */, + CDB5A7372122DDD4001DB39B /* UITextView.swift in Sources */, + CDB5A73E2122DDD4001DB39B /* TableViewCellType.swift in Sources */, + CDB5A7362122DDD4001DB39B /* UILabel.swift in Sources */, + CDB5A73C2122DDD4001DB39B /* UITableView.swift in Sources */, + CDB5A7382122DDD4001DB39B /* CollectionViewCellType.swift in Sources */, + CDB5A7332122DDD4001DB39B /* KVO.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -258,6 +424,7 @@ }; CDB5A71B2122DD6A001DB39B /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 574C6916EBC97E1CA06977B3 /* Pods-RxSwiftExtensions.debug.xcconfig */; buildSettings = { CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; @@ -283,6 +450,7 @@ }; CDB5A71C2122DD6A001DB39B /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 52DEE5AAECDF48D200F246BA /* Pods-RxSwiftExtensions.release.xcconfig */; buildSettings = { CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; diff --git a/RxSwiftExtensions/RxSwiftExtensions.h b/RxSwiftExtensions/RxSwiftExtensions.h index 5200c05..8ba923a 100644 --- a/RxSwiftExtensions/RxSwiftExtensions.h +++ b/RxSwiftExtensions/RxSwiftExtensions.h @@ -2,7 +2,7 @@ // RxSwiftExtensions.h // RxSwiftExtensions // -// Created by Joonghyun-Yoon on 2018. 8. 14.. +// Created by tokijh on 2018. 8. 14.. // Copyright © 2018년 tokijh. All rights reserved. // diff --git a/RxSwiftExtensions/Swift/KVO/KVO.swift b/RxSwiftExtensions/Swift/KVO/KVO.swift new file mode 100644 index 0000000..ab10373 --- /dev/null +++ b/RxSwiftExtensions/Swift/KVO/KVO.swift @@ -0,0 +1,30 @@ +// +// KVO.swift +// RxSwiftExtensions +// +// Created by tokijh on 2018. 8. 14.. +// Copyright © 2018년 tokijh. All rights reserved. +// + +#if !os(Linux) + +import Foundation.NSObject +import RxSwift +import RxCocoa + +extension Reactive where Base: NSObject { + public func observe(keyPath: KeyPath, options: KeyValueObservingOptions = [.new, .initial], retainSelf: Bool = true) -> Observable { + return self.observe(Value.self, keyPath._kvcKeyPathString!, options: options, retainSelf: retainSelf) + } +} + +#if !DISABLE_SWIZZLING && !os(Linux) +extension Reactive where Base: NSObject { + public func observeWeakly(keyPath: KeyPath, options: KeyValueObservingOptions = [.new, .initial]) -> Observable { + return self.observeWeakly(Value.self, keyPath._kvcKeyPathString!, options: options) + } +} + +#endif + +#endif diff --git a/RxSwiftExtensions/UIKit/UIView/UICollectionView/CollectionViewCellType.swift b/RxSwiftExtensions/UIKit/UIView/UICollectionView/CollectionViewCellType.swift new file mode 100644 index 0000000..dfbad1d --- /dev/null +++ b/RxSwiftExtensions/UIKit/UIView/UICollectionView/CollectionViewCellType.swift @@ -0,0 +1,11 @@ +// +// CollectionViewCellType.swift +// RxSwiftExtensions +// +// Created by tokijh on 2018. 8. 14.. +// Copyright © 2018년 tokijh. All rights reserved. +// + +protocol CollectionViewCellType { + static var Identifier: String { get } +} diff --git a/RxSwiftExtensions/UIKit/UIView/UICollectionView/UICollectionReusableView.swift b/RxSwiftExtensions/UIKit/UIView/UICollectionView/UICollectionReusableView.swift new file mode 100644 index 0000000..5f3a2f5 --- /dev/null +++ b/RxSwiftExtensions/UIKit/UIView/UICollectionView/UICollectionReusableView.swift @@ -0,0 +1,14 @@ +// +// UICollectionReusableView.swift +// RxSwiftExtensions +// +// Created by tokijh on 2018. 8. 14.. +// Copyright © 2018년 tokijh. All rights reserved. +// + +import UIKit + +extension UICollectionReusableView: CollectionViewCellType { + static var Identifier: String { return String(describing: self.self) } +} + diff --git a/RxSwiftExtensions/UIKit/UIView/UICollectionView/UICollectionView.swift b/RxSwiftExtensions/UIKit/UIView/UICollectionView/UICollectionView.swift new file mode 100644 index 0000000..85424ba --- /dev/null +++ b/RxSwiftExtensions/UIKit/UIView/UICollectionView/UICollectionView.swift @@ -0,0 +1,35 @@ +// +// UICollectionView.swift +// RxSwiftExtensions +// +// Created by tokijh on 2018. 8. 14.. +// Copyright © 2018년 tokijh. All rights reserved. +// + +import UIKit + +extension UICollectionView { + func register(cell: Cell.Type, forCellWithReuseIdentifier reuseIdentifier: String = Cell.Identifier) where Cell: UICollectionViewCell { + register(cell, forCellWithReuseIdentifier: reuseIdentifier) + } + + func register(nibCell: Cell.Type, forCellWithReuseIdentifier reuseIdentifier: String = Cell.Identifier) where Cell: UICollectionViewCell { + register(UINib(nibName: nibCell.Identifier, bundle: nil), forCellWithReuseIdentifier: reuseIdentifier) + } + + func register(cell: Cell.Type, forSupplementaryViewOfKind kind: String, withReuseIdentifier reuseIdentifier: String = Cell.Identifier) where Cell: UICollectionReusableView { + register(cell, forSupplementaryViewOfKind: kind, withReuseIdentifier: reuseIdentifier) + } + + func register(nibCell: Cell.Type, forSupplementaryViewOfKind kind: String, withReuseIdentifier reuseIdentifier: String = Cell.Identifier) where Cell: UICollectionReusableView { + register(UINib(nibName: nibCell.Identifier, bundle: nil), forSupplementaryViewOfKind: kind, withReuseIdentifier: reuseIdentifier) + } + + func dequeue(_ reuseableCell: Cell.Type, for indexPath: IndexPath) -> Cell? where Cell: UICollectionViewCell { + return dequeueReusableCell(withReuseIdentifier: reuseableCell.Identifier, for: indexPath) as? Cell + } + + func dequeue(_ reuseableCell: Cell.Type, ofKind kind: String, for indexPath: IndexPath) -> Cell? where Cell: UICollectionReusableView { + return dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: reuseableCell.Identifier, for: indexPath) as? Cell + } +} diff --git a/RxSwiftExtensions/UIKit/UIView/UILabel/UILabel.swift b/RxSwiftExtensions/UIKit/UIView/UILabel/UILabel.swift new file mode 100644 index 0000000..9c643f3 --- /dev/null +++ b/RxSwiftExtensions/UIKit/UIView/UILabel/UILabel.swift @@ -0,0 +1,19 @@ +// +// UILabel.swift +// RxSwiftExtensions +// +// Created by tokijh on 2018. 8. 14.. +// Copyright © 2018년 tokijh. All rights reserved. +// + +import UIKit +import RxSwift +import RxCocoa + +extension Reactive where Base: UILabel { + var textColor: Binder { + return Binder(base, binding: { (base, color) in + base.textColor = color + }) + } +} diff --git a/RxSwiftExtensions/UIKit/UIView/UIScrollView/UIScrollView.swift b/RxSwiftExtensions/UIKit/UIView/UIScrollView/UIScrollView.swift new file mode 100644 index 0000000..740f306 --- /dev/null +++ b/RxSwiftExtensions/UIKit/UIView/UIScrollView/UIScrollView.swift @@ -0,0 +1,32 @@ +// +// UIScrollView.swift +// RxSwiftExtensions +// +// Created by tokijh on 2018. 8. 14.. +// Copyright © 2018년 tokijh. All rights reserved. +// + +import UIKit +import RxSwift +import RxCocoa +import RxOptional + +extension Reactive where Base: UIScrollView { + var contentSize: Observable { + return self.observeWeakly(keyPath: \.contentSize, options: [.initial, .new]).filterNil() + } + + var scrollableVertical: Observable { + return self.contentSize + .withLatestFrom(self.bounds) { (contentSize, bounds) -> Bool in + bounds.height < contentSize.height + } + } + + var scrollableHorizontal: Observable { + return self.contentSize + .withLatestFrom(self.bounds) { (contentSize, bounds) -> Bool in + bounds.width < contentSize.width + } + } +} diff --git a/RxSwiftExtensions/UIKit/UIView/UITableView/TableViewCellType.swift b/RxSwiftExtensions/UIKit/UIView/UITableView/TableViewCellType.swift new file mode 100644 index 0000000..c2e40f8 --- /dev/null +++ b/RxSwiftExtensions/UIKit/UIView/UITableView/TableViewCellType.swift @@ -0,0 +1,11 @@ +// +// TableViewCellType.swift +// RxSwiftExtensions +// +// Created by tokijh on 2018. 8. 14.. +// Copyright © 2018년 tokijh. All rights reserved. +// + +protocol TableViewCellType { + static var Identifier: String { get } +} diff --git a/RxSwiftExtensions/UIKit/UIView/UITableView/UITableView.swift b/RxSwiftExtensions/UIKit/UIView/UITableView/UITableView.swift new file mode 100644 index 0000000..9212337 --- /dev/null +++ b/RxSwiftExtensions/UIKit/UIView/UITableView/UITableView.swift @@ -0,0 +1,39 @@ +// +// UITableView.swift +// RxSwiftExtensions +// +// Created by tokijh on 2018. 8. 14.. +// Copyright © 2018년 tokijh. All rights reserved. +// + +import UIKit + +extension UITableView { + func register(cell: Cell.Type, forCellReuseIdentifier reuseIdentifier: String = Cell.Identifier) where Cell: UITableViewCell { + register(cell, forCellReuseIdentifier: reuseIdentifier) + } + + func register(nibCell: Cell.Type, forCellReuseIdentifier reuseIdentifier: String = Cell.Identifier) where Cell: UITableViewCell { + register(UINib(nibName: nibCell.Identifier, bundle: nil), forCellReuseIdentifier: reuseIdentifier) + } + + func register(cell: Cell.Type, forHeaderFooterViewReuseIdentifier reuseIdentifier: String = Cell.Identifier) where Cell: UITableViewHeaderFooterView { + register(cell, forHeaderFooterViewReuseIdentifier: reuseIdentifier) + } + + func register(nibCell: Cell.Type, forHeaderFooterViewReuseIdentifier reuseIdentifier: String = Cell.Identifier) where Cell: UITableViewHeaderFooterView { + register(UINib(nibName: nibCell.Identifier, bundle: nil), forHeaderFooterViewReuseIdentifier: reuseIdentifier) + } + + func dequeue(_ reusableCell: Cell.Type) -> Cell? where Cell: UITableViewCell { + return dequeueReusableCell(withIdentifier: reusableCell.Identifier) as? Cell + } + + func dequeue(_ resusableCell: Cell.Type, indexPath: IndexPath) -> Cell? where Cell: UITableViewCell { + return dequeueReusableCell(withIdentifier: resusableCell.Identifier, for: indexPath) as? Cell + } + + func dequeue(_ reusableCell: Cell.Type) -> Cell? where Cell: UITableViewHeaderFooterView { + return dequeueReusableHeaderFooterView(withIdentifier: reusableCell.Identifier) as? Cell + } +} diff --git a/RxSwiftExtensions/UIKit/UIView/UITableView/UITableViewCell.swift b/RxSwiftExtensions/UIKit/UIView/UITableView/UITableViewCell.swift new file mode 100644 index 0000000..c4d519e --- /dev/null +++ b/RxSwiftExtensions/UIKit/UIView/UITableView/UITableViewCell.swift @@ -0,0 +1,13 @@ +// +// UITableViewCell.swift +// RxSwiftExtensions +// +// Created by tokijh on 2018. 8. 14.. +// Copyright © 2018년 tokijh. All rights reserved. +// + +import UIKit + +extension UITableViewCell: TableViewCellType { + static var Identifier: String { return String(describing: self.self) } +} diff --git a/RxSwiftExtensions/UIKit/UIView/UITableView/UITableViewHeaderFooterView.swift b/RxSwiftExtensions/UIKit/UIView/UITableView/UITableViewHeaderFooterView.swift new file mode 100644 index 0000000..e4f688e --- /dev/null +++ b/RxSwiftExtensions/UIKit/UIView/UITableView/UITableViewHeaderFooterView.swift @@ -0,0 +1,13 @@ +// +// UITableViewHeaderFooterView.swift +// RxSwiftExtensions +// +// Created by tokijh on 2018. 8. 14.. +// Copyright © 2018년 tokijh. All rights reserved. +// + +import UIKit + +extension UITableViewHeaderFooterView: TableViewCellType { + static var Identifier: String { return String(describing: self.self) } +} diff --git a/RxSwiftExtensions/UIKit/UIView/UITextView/UITextView.swift b/RxSwiftExtensions/UIKit/UIView/UITextView/UITextView.swift new file mode 100644 index 0000000..0c7deec --- /dev/null +++ b/RxSwiftExtensions/UIKit/UIView/UITextView/UITextView.swift @@ -0,0 +1,19 @@ +// +// UITextView.swift +// RxSwiftExtensions +// +// Created by tokijh on 2018. 8. 14.. +// Copyright © 2018년 tokijh. All rights reserved. +// + +import UIKit +import RxSwift +import RxCocoa + +extension Reactive where Base: UITextView { + var textColor: Binder { + return Binder(base, binding: { (base, color) in + base.textColor = color + }) + } +} diff --git a/RxSwiftExtensions/UIKit/UIView/UIView.swift b/RxSwiftExtensions/UIKit/UIView/UIView.swift new file mode 100644 index 0000000..c9099fc --- /dev/null +++ b/RxSwiftExtensions/UIKit/UIView/UIView.swift @@ -0,0 +1,22 @@ +// +// UIView.swift +// RxSwiftExtensions +// +// Created by tokijh on 2018. 8. 14.. +// Copyright © 2018년 tokijh. All rights reserved. +// + +import UIKit +import RxSwift +import RxCocoa +import RxOptional + +extension Reactive where Base: UIView { + var bounds: Observable { + return self.observeWeakly(keyPath: \.bounds, options: [.initial, .new]).filterNil() + } + + var center: Observable { + return self.observeWeakly(keyPath: \.center, options: [.initial, .new]).filterNil() + } +}