In swift three the current valid versoin for Eureka is 2.0.0-beta.1, you could use cocoapods in order to use the library in your ios10 projects with the following command
1 |
pod 'Eureka', "~> 2.0.0-beta.1" |
Here is an example of the below script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
// // OrdersStepOneVC.swift // iOSMindizorApp // // Created by AHMAD NASER on 2/10/17. // Copyright © 2017 Ahmad Naser Turnkey Solutions LLC. All rights reserved. // import UIKit import Eureka import Alamofire import SwiftSpinner class OrdersStepOneVC: FormViewController { override func viewDidLoad() { super.viewDidLoad() Section(){ section in section.header = { var header = HeaderFooterView<UIView>(.callback({ let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) view.backgroundColor = .red return view })) header.height = { 100 } return header }() } form +++ Section("Section1") <<< TextRow(){ row in row.title = "Text Row" row.placeholder = "Enter text here" } <<< SegmentedRow<String>("gender"){ $0.options = ["male", "female"] $0.title = "m" $0.value = "f" }.onChange{ row in print(row.value) } <<< PhoneRow(){ $0.title = "Phone Row" $0.placeholder = "And numbers here" } +++ Section("Section2") <<< DateRow(){ $0.title = "Date Row" $0.value = NSDate(timeIntervalSinceReferenceDate: 0) as Date } <<< SwitchRow("switchRowTag"){ $0.title = "Show message" } <<< LabelRow(){ $0.hidden = Condition.function(["switchRowTag"], { form in return !((form.rowBy(tag: "switchRowTag") as? SwitchRow)?.value ?? false) }) $0.title = "Switch is on!" form +++ Section("Multiple Choices") <<< MultipleSelectorRow<String>() { $0.title = "Favourite Foods" $0.options = ["🍝", "🍟", "🍕", "🍚"] $0.value = ["🍝", "🍕" ] } form +++ Section("Languages") <<< MultipleSelectorRow<String>() { $0.title = "Choosed langs" $0.options = ["dn","er", "ec", "en", "ar"] $0.value = ["dn", "er" ] } form +++ Section("Login Form") <<< TextRow() { $0.placeholder = "Username" } <<< PasswordRow() { $0.placeholder = "Password" } <<< ButtonRow() { $0.title = "Login" $0.onCellSelection { cell, row in self.presentAlert(message: "Will login") } } } addFormWithToggle(toForm: form) let continents = ["Africa", "Antarctica", "Asia", "Australia", "Europe", "North America", "South America"] form +++ SelectableSection<ListCheckRow<String>>("Where do you live", selectionType: .multipleSelection) for option in continents { form.last! <<< ListCheckRow<String>(option){ listRow in listRow.title = option listRow.selectableValue = option listRow.value = nil } } let itemNames = ["one","two","three"] // Eureka From Set-up form +++ Section("Select item values") for itemName in itemNames{ form.last! <<< TextRow() { $0.title = itemName $0.placeholder = itemName } } // Eureka From Set-up form +++ Section("Select item values") for itemName in itemNames{ form.last! <<< StepperRow() { $0.tag = itemName $0.title = itemName $0.value = 0 } } } private func addFormWithToggle(toForm form: Form) { let switchRowTag = "switch_row" let setStartDateRowTag = "set_start_date_time" let setEndDateRowTag = "set_end_date_time" let switchRow = SwitchRow(switchRowTag) { $0.title = "All Day Event" $0.value = true } let hiddenCondition = Condition.function([switchRowTag]) { form in guard let switchCell = form.rowBy(tag:switchRowTag) as? SwitchRow else { return false } return switchCell.value == true } let s = Section() s.append(switchRow) s.append(DateTimeInlineRow(setStartDateRowTag) { $0.title = "Starts" $0.value = NSDate.oneHourFromNow() as Date $0.hidden = hiddenCondition }) s.append(DateTimeInlineRow(setEndDateRowTag) { $0.title = "Ends" $0.value = NSDate.hoursFormNow(numberOfHours: 4) as Date $0.hidden = hiddenCondition }) form.append(s) } private func presentAlert(title: String? = nil, message: String) { let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) self.present(alertController, animated: true, completion: nil) } } extension NSDate { static func oneHourFromNow() -> NSDate { return NSDate.hoursFormNow(numberOfHours: 1) } static func hoursFormNow(numberOfHours: Int) -> NSDate { let interval = Double(numberOfHours) * 60 return NSDate().addingTimeInterval(interval) } } |