-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from k-lpmg/bugfix-perform
Bugfix perform
- Loading branch information
Showing
14 changed files
with
318 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// AppNavigator.swift | ||
// RealmWrapperExample | ||
// | ||
// Created by DongHeeKang on 20/02/2019. | ||
// Copyright © 2019 k-lpmg. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
final class AppNavigator { | ||
|
||
static let shared = AppNavigator() | ||
|
||
// MARK: - Internal methods | ||
|
||
func start(with window: UIWindow) { | ||
let controller = TableViewController() | ||
let navigationController = UINavigationController(rootViewController: controller) | ||
window.rootViewController = navigationController | ||
window.backgroundColor = .white | ||
window.makeKeyAndVisible() | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import UIKit | ||
|
||
extension UITableView { | ||
|
||
func registerWithCellReuseIdentifier<CellClass: UITableViewCell>(_ cellClass: CellClass.Type) { | ||
self.register(cellClass, forCellReuseIdentifier: cellClass.className) | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
Example/Sources/Extension/UIViewController-Extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import UIKit | ||
|
||
extension UIViewController { | ||
func alert(title: String? = nil, message: String? = nil, preferredStyle: UIAlertController.Style = .alert, actions: [UIAlertAction]?, completion: (() -> Void)? = nil) { | ||
let alert = UIAlertController(title: title, message: message, preferredStyle: preferredStyle) | ||
if let actions = actions { | ||
actions.forEach({ (action) in | ||
alert.addAction(action) | ||
}) | ||
} | ||
present(alert, animated: true, completion: completion) | ||
} | ||
|
||
} |
161 changes: 161 additions & 0 deletions
161
Example/Sources/ViewControllers/MultipleAddViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import UIKit | ||
|
||
import RealmSwift | ||
import RealmWrapper | ||
|
||
final class MultipleAddViewController: UIViewController { | ||
|
||
// MARK: - Properties | ||
|
||
private var isCountValid: Bool = false { | ||
didSet { | ||
saveButtonItem.isEnabled = isCountValid | ||
} | ||
} | ||
private let useSyncLabel: UILabel = { | ||
let label = UILabel() | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
label.font = UIFont.systemFont(ofSize: 15, weight: .bold) | ||
label.text = "Use Sync" | ||
return label | ||
}() | ||
private let useSyncSwitch: UISwitch = { | ||
let uiSwitch = UISwitch() | ||
uiSwitch.translatesAutoresizingMaskIntoConstraints = false | ||
return uiSwitch | ||
}() | ||
private let useInMemoryLabel: UILabel = { | ||
let label = UILabel() | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
label.font = UIFont.systemFont(ofSize: 15, weight: .bold) | ||
label.text = "Use InMemory" | ||
return label | ||
}() | ||
private let useInMemorySwitch: UISwitch = { | ||
let uiSwitch = UISwitch() | ||
uiSwitch.translatesAutoresizingMaskIntoConstraints = false | ||
return uiSwitch | ||
}() | ||
private let countLabel: UILabel = { | ||
let label = UILabel() | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
label.font = UIFont.systemFont(ofSize: 15, weight: .bold) | ||
label.text = "Count" | ||
return label | ||
}() | ||
private let countTextField: UITextField = { | ||
let textField = UITextField() | ||
textField.translatesAutoresizingMaskIntoConstraints = false | ||
textField.keyboardType = .numberPad | ||
textField.textAlignment = .right | ||
textField.layer.borderColor = UIColor.gray.cgColor | ||
textField.layer.borderWidth = 0.5 | ||
return textField | ||
}() | ||
|
||
private lazy var saveButtonItem: UIBarButtonItem = { | ||
let buttonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(saveButtonDidClicked)) | ||
buttonItem.isEnabled = false | ||
return buttonItem | ||
}() | ||
|
||
// MARK: - Overridden: UIViewController | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
setNavigation() | ||
setProperties() | ||
setSelector() | ||
view.addSubview(useSyncLabel) | ||
view.addSubview(useSyncSwitch) | ||
view.addSubview(useInMemoryLabel) | ||
view.addSubview(useInMemorySwitch) | ||
view.addSubview(countLabel) | ||
view.addSubview(countTextField) | ||
layout() | ||
} | ||
|
||
// MARK: - Private methods | ||
|
||
private func setNavigation() { | ||
title = "Add multiple user" | ||
if #available(iOS 11.0, *) { | ||
navigationItem.largeTitleDisplayMode = .never | ||
} | ||
navigationItem.rightBarButtonItem = saveButtonItem | ||
} | ||
|
||
private func setProperties() { | ||
view.backgroundColor = .white | ||
} | ||
|
||
private func setSelector() { | ||
countTextField.addTarget(self, action: #selector(countTextFieldEditingChanged(sender:)), for: .editingChanged) | ||
} | ||
|
||
// MARK: - Private selector | ||
|
||
@objc private func countTextFieldEditingChanged(sender: UITextField) { | ||
guard let text = sender.text else {return} | ||
|
||
isCountValid = !text.isEmpty | ||
} | ||
|
||
@objc private func saveButtonDidClicked() { | ||
guard let text = countTextField.text, let count = Int(text) else {return} | ||
|
||
let useInMemory = useInMemorySwitch.isOn | ||
let useSync = useSyncSwitch.isOn | ||
|
||
DispatchQueue.global().async { | ||
var users = [User]() | ||
(0...count).forEach({ (i) in | ||
let user = User(name: "\(i)", age: i) | ||
users.append(user) | ||
|
||
print("Appended users count : \(users.count)") | ||
}) | ||
|
||
if useInMemory { | ||
UserInMemoryRealmProxy().append(users, isSync: useSync) | ||
} else { | ||
UserRealmProxy().append(users, isSync: useSync) | ||
} | ||
} | ||
navigationController?.popViewController(animated: true) | ||
} | ||
|
||
} | ||
|
||
// MARK: - Layout | ||
|
||
extension MultipleAddViewController { | ||
|
||
private func layout() { | ||
useSyncLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16).isActive = true | ||
useSyncLabel.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 32).isActive = true | ||
useSyncLabel.widthAnchor.constraint(equalToConstant: 120).isActive = true | ||
|
||
useSyncSwitch.topAnchor.constraint(equalTo: useSyncLabel.topAnchor).isActive = true | ||
useSyncSwitch.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16).isActive = true | ||
|
||
useInMemoryLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16).isActive = true | ||
useInMemoryLabel.topAnchor.constraint(equalTo: useSyncLabel.bottomAnchor, constant: 32).isActive = true | ||
useInMemoryLabel.widthAnchor.constraint(equalToConstant: 120).isActive = true | ||
|
||
useInMemorySwitch.topAnchor.constraint(equalTo: useInMemoryLabel.topAnchor).isActive = true | ||
useInMemorySwitch.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16).isActive = true | ||
|
||
countLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16).isActive = true | ||
countLabel.topAnchor.constraint(equalTo: useInMemoryLabel.bottomAnchor, constant: 32).isActive = true | ||
countLabel.widthAnchor.constraint(equalToConstant: 120).isActive = true | ||
|
||
countTextField.topAnchor.constraint(equalTo: countLabel.topAnchor).isActive = true | ||
countTextField.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16).isActive = true | ||
countTextField.widthAnchor.constraint(equalToConstant: 85).isActive = true | ||
countTextField.heightAnchor.constraint(equalToConstant: 32).isActive = true | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.