Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@ platform :ios, '8.0'

target 'RxTodo' do
use_frameworks!
inhibit_all_warnings!

# Rx
pod 'RxSwift', '2.5.0'
pod 'RxCocoa', '2.5.0'
pod 'RxDataSources', '0.8.1'
pod 'RxSwift', '3.3.1'
pod 'RxCocoa', '3.3.1'
pod 'RxDataSources', '1.0.3'
pod 'RxSwiftExt', '2.1.0'

# UI
pod 'SnapKit', '0.21.1'
pod 'ManualLayout', '1.2.1'
pod 'SnapKit', '3.2.0'
pod 'ManualLayout', '1.3.0'

# Misc.
pod 'Then', '1.0.3'
pod 'ReusableKit', '0.3.0'
pod 'CGFloatLiteral', '0.1.0'
pod 'Then', '2.1.0'
pod 'ReusableKit', '1.1.0'
pod 'CGFloatLiteral', '0.3.0'

end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
12 changes: 11 additions & 1 deletion RxTodo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = "Suyeol Jeon";
TargetAttributes = {
03D0C0AE1D269F7900EE93D5 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0820;
};
};
};
Expand Down Expand Up @@ -367,8 +368,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -412,8 +415,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -432,6 +437,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -440,23 +446,27 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 92FD2F879471E3FA186E82B7 /* Pods-RxTodo.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/RxTodo/Support/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = kr.xoul.RxTodo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
03D0C0C31D269F7900EE93D5 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 2C8D148321B73000A720563F /* Pods-RxTodo.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/RxTodo/Support/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = kr.xoul.RxTodo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
8 changes: 4 additions & 4 deletions RxTodo/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
window.backgroundColor = .whiteColor()
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
window.backgroundColor = .white
window.makeKeyAndVisible()

let viewModel = TaskListViewModel()
Expand Down
6 changes: 3 additions & 3 deletions RxTodo/Sources/Models/ModelType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ protocol Identifiable {
protocol ModelType: Then {
}

extension CollectionType where Generator.Element: Identifiable {
extension Collection where Iterator.Element: Identifiable {

func indexOf(element: Self.Generator.Element) -> Self.Index? {
return self.indexOf { $0.id == element.id }
func indexOf(_ element: Self.Iterator.Element) -> Self.Index? {
return self.index { $0.id == element.id }
}

}
4 changes: 2 additions & 2 deletions RxTodo/Sources/Models/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import Foundation

struct Task: ModelType, Identifiable {
class Task: ModelType, Identifiable {

var id: String = NSUUID().UUIDString
var id: String = UUID().uuidString
var title: String
var memo: String?

Expand Down
41 changes: 10 additions & 31 deletions RxTodo/Sources/Rx/RxOperators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,35 @@
import Foundation
#if !RX_NO_MODULE
import RxSwift
import RxSwiftExt
import RxCocoa
#endif

import UIKit

// Two way binding operator between control property and variable, that's all it takes {

infix operator <-> {
}

func nonMarkedText(textInput: UITextInput) -> String? {
let start = textInput.beginningOfDocument
let end = textInput.endOfDocument

guard let rangeAll = textInput.textRangeFromPosition(start, toPosition: end),
text = textInput.textInRange(rangeAll) else {
return nil
}

guard let markedTextRange = textInput.markedTextRange else {
return text
}

guard let startRange = textInput.textRangeFromPosition(start, toPosition: markedTextRange.start),
endRange = textInput.textRangeFromPosition(markedTextRange.end, toPosition: end) else {
return text
}

return (textInput.textInRange(startRange) ?? "") + (textInput.textInRange(endRange) ?? "")
}
infix operator <->

func <-> (textInput: RxTextInput, variable: Variable<String>) -> Disposable {
func <-> (textInput: UITextField, variable: Variable<String>) -> Disposable {
let bindToUIDisposable = variable.asObservable()
.bindTo(textInput.rx_text)
let bindToVariable = textInput.rx_text
.bindTo(textInput.rx.text)
let bindToVariable = textInput.rx.text
.subscribe(onNext: { [weak textInput] n in
guard let textInput = textInput else {
return
}

let nonMarkedTextValue = nonMarkedText(textInput)
let inputText = textInput.text

if nonMarkedTextValue != variable.value {
variable.value = nonMarkedTextValue ?? ""
if inputText != variable.value {
variable.value = inputText ?? ""
}
}, onCompleted: {
bindToUIDisposable.dispose()
})

return StableCompositeDisposable.create(bindToUIDisposable, bindToVariable)
return CompositeDisposable(bindToUIDisposable, bindToVariable)
}

func <-> <T>(property: ControlProperty<T>, variable: Variable<T>) -> Disposable {
Expand All @@ -81,7 +60,7 @@ func <-> <T>(property: ControlProperty<T>, variable: Variable<T>) -> Disposable
bindToUIDisposable.dispose()
})

return StableCompositeDisposable.create(bindToUIDisposable, bindToVariable)
return CompositeDisposable(bindToUIDisposable, bindToVariable)
}

// }
12 changes: 6 additions & 6 deletions RxTodo/Sources/Services/ModelService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import RxSwift

private var _instances = [String: Any]()

struct ModelService<Model: ModelType> {
class ModelService<Model: ModelType> {

let didCreate = PublishSubject<Model>()
let didUpdate = PublishSubject<Model>()
let didDelete = PublishSubject<Model>()

static func instance(modelClass: Model.Type) -> ModelService<Model> {
let key = String(modelClass)
static func instance(_ modelClass: Model.Type) -> ModelService<Model> {
let key = String(describing: modelClass)
if let stream = _instances[key] as? ModelService<Model> {
return stream
}
Expand All @@ -31,15 +31,15 @@ struct ModelService<Model: ModelType> {
extension ModelType {

static var didCreate: PublishSubject<Self> {
return ModelService.instance(Self).didCreate
return ModelService.instance(Self.self).didCreate
}

static var didUpdate: PublishSubject<Self> {
return ModelService.instance(Self).didUpdate
return ModelService.instance(Self.self).didUpdate
}

static var didDelete: PublishSubject<Self> {
return ModelService.instance(Self).didDelete
return ModelService.instance(Self.self).didDelete
}

}
10 changes: 5 additions & 5 deletions RxTodo/Sources/Utils/Snap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
import UIKit

/// Ceil to snap pixel
func snap(x: CGFloat) -> CGFloat {
let scale = UIScreen.mainScreen().scale
func snap(_ x: CGFloat) -> CGFloat {
let scale = UIScreen.main.scale
return ceil(x * scale) / scale
}

func snap(point: CGPoint) -> CGPoint {
func snap(_ point: CGPoint) -> CGPoint {
return CGPoint(x: snap(point.x), y: snap(point.y))
}

func snap(size: CGSize) -> CGSize {
func snap(_ size: CGSize) -> CGSize {
return CGSize(width: snap(size.width), height: snap(size.height))
}

func snap(rect: CGRect) -> CGRect {
func snap(_ rect: CGRect) -> CGRect {
return CGRect(origin: snap(rect.origin), size: snap(rect.size))
}
16 changes: 8 additions & 8 deletions RxTodo/Sources/Utils/String+BoundingRect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import UIKit

extension String {

func boundingRectWithSize(size: CGSize, attributes: [String: AnyObject]) -> CGRect {
let options: NSStringDrawingOptions = [.UsesLineFragmentOrigin, .UsesFontLeading]
return snap(self.boundingRectWithSize(size, options: options, attributes: attributes, context: nil))
func boundingRectWithSize(_ size: CGSize, attributes: [String: AnyObject]) -> CGRect {
let options: NSStringDrawingOptions = [.usesLineFragmentOrigin, .usesFontLeading]
return snap(self.boundingRect(with: size, options: options, attributes: attributes, context: nil))
}

func sizeThatFits(size: CGSize, font: UIFont, maximumNumberOfLines: Int = 0) -> CGSize {
func sizeThatFits(_ size: CGSize, font: UIFont, maximumNumberOfLines: Int = 0) -> CGSize {
let attributes = [NSFontAttributeName: font]
var size = self.boundingRectWithSize(size, attributes: attributes).size
if maximumNumberOfLines > 0 {
Expand All @@ -24,13 +24,13 @@ extension String {
return snap(size)
}

func widthWithFont(font: UIFont, maximumNumberOfLines: Int = 0) -> CGFloat {
let size = CGSize(width: CGFloat.max, height: CGFloat.max)
func widthWithFont(_ font: UIFont, maximumNumberOfLines: Int = 0) -> CGFloat {
let size = CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
return snap(self.sizeThatFits(size, font: font, maximumNumberOfLines: maximumNumberOfLines).width)
}

func heightThatFitsWidth(width: CGFloat, font: UIFont, maximumNumberOfLines: Int = 0) -> CGFloat {
let size = CGSize(width: width, height: CGFloat.max)
func heightThatFitsWidth(_ width: CGFloat, font: UIFont, maximumNumberOfLines: Int = 0) -> CGFloat {
let size = CGSize(width: width, height: CGFloat.greatestFiniteMagnitude)
return snap(self.sizeThatFits(size, font: font, maximumNumberOfLines: maximumNumberOfLines).height)
}

Expand Down
2 changes: 1 addition & 1 deletion RxTodo/Sources/ViewControllers/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BaseViewController: UIViewController {

// MARK: Layout Constraints

private(set) var didSetupConstraints = false
fileprivate(set) var didSetupConstraints = false

override func viewDidLoad() {
self.view.setNeedsUpdateConstraints()
Expand Down
Loading