Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.
Merged
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
43 changes: 21 additions & 22 deletions Basic-Swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

if let JSON = NSJSONSerialization.JSONObjectWithContentsOfFile("forms.json") as? [String : AnyObject] {
let initialValues = [
"address" : "Burger Park 667",
"end_date" : "2017-10-31 23:00:00 +00:00",
"first_name" : "Ola",
"last_name" : "Nordman",
"start_date" : "2014-10-31 23:00:00 +00:00"]
let sampleController = SampleCollectionViewController(JSON: JSON, initialValues: initialValues)
let rootViewController = UINavigationController(rootViewController: sampleController)

rootViewController.view.tintColor = UIColor(hex: "5182AF")
rootViewController.navigationBarHidden = true

FORMDefaultStyle.applyStyle()

self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = rootViewController
self.window?.makeKeyAndVisible()
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)

let JSON = JSONSerialization.jsonObject(withContentsOfFile: "forms.json") as! [String : AnyObject]
let initialValues = [
"address" : "Burger Park 667",
"end_date" : "2017-10-31 23:00:00 +00:00",
"first_name" : "Ola",
"last_name" : "Nordman",
"start_date" : "2014-10-31 23:00:00 +00:00"]
let sampleController = SampleCollectionViewController(JSON: JSON, initialValues: initialValues as [String : AnyObject])
let rootViewController = UINavigationController(rootViewController: sampleController)

rootViewController.view.tintColor = UIColor(hex: "5182AF")
rootViewController.isNavigationBarHidden = true

FORMDefaultStyle.apply()

self.window?.rootViewController = rootViewController
self.window?.makeKeyAndVisible()

return true
}

Expand Down
30 changes: 15 additions & 15 deletions Basic-Swift/SampleCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Form.FORMViewController
class SampleCollectionViewController: FORMViewController {

init(JSON: [String : AnyObject], initialValues: [String : AnyObject]) {
super.init(JSON: JSON, andInitialValues: initialValues, disabled:true)
super.init(json: JSON, andInitialValues: initialValues, disabled:true)
}

required init?(coder aDecoder: NSCoder) {
Expand All @@ -19,37 +19,37 @@ class SampleCollectionViewController: FORMViewController {
self.collectionView?.backgroundColor = UIColor(hex: "DAE2EA")
}

override func viewDidAppear(animated: Bool) {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

let validateButtonItem = UIBarButtonItem(title: "Validate",
style: .Done,
style: .done,
target: self,
action: NSSelectorFromString("validateButtonAction"))

let updateButtonItem = UIBarButtonItem(title: "Update",
style: .Done,
style: .done,
target: self,
action: NSSelectorFromString("updateButtonAction"))

let flexibleBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace,
let flexibleBarButtonItem = UIBarButtonItem(barButtonSystemItem: .flexibleSpace,
target: nil,
action: nil)

let readOnlyView = UIView(frame: CGRectMake(0.0, 0.0, 150.0, 40.0))
let readOnlyLabel = UILabel(frame: CGRectMake(0.0, 0.0, 90.0, 40.0))
let readOnlyView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 150.0, height: 40.0))
let readOnlyLabel = UILabel(frame: CGRect(x: 0.0, y: 0.0, width: 90.0, height: 40.0))
readOnlyLabel.text = "Read-Only"
readOnlyLabel.textColor = UIColor(hex: "5182AF")
readOnlyLabel.font = UIFont.boldSystemFontOfSize(17.0)
readOnlyLabel.font = UIFont.boldSystemFont(ofSize: 17.0)

readOnlyView.addSubview(readOnlyLabel)

let readOnlySwitch = UISwitch(frame: CGRectMake(90.0, 5.0, 40.0, 40.0))
let readOnlySwitch = UISwitch(frame: CGRect(x: 90.0, y: 5.0, width: 40.0, height: 40.0))
readOnlySwitch.tintColor = UIColor(hex: "5182AF")
readOnlySwitch.on = true
readOnlySwitch.isOn = true
readOnlySwitch.addTarget(self,
action: NSSelectorFromString("readOnly:"),
forControlEvents: .ValueChanged)
for: .valueChanged)

readOnlyView.addSubview(readOnlySwitch)

Expand All @@ -62,16 +62,16 @@ class SampleCollectionViewController: FORMViewController {

// MARK: Actions

func readOnly(sender: UISwitch) {
if sender.on {
func readOnly(_ sender: UISwitch) {
if sender.isOn {
self.dataSource.disable()
} else {
self.dataSource.enable()
}
}

func validateButtonAction() {
if self.dataSource.valid {
if self.dataSource.isValid {
UIAlertView(title: "Everything is valid, you get a 🍬!",
message: nil,
delegate: nil,
Expand All @@ -82,7 +82,7 @@ class SampleCollectionViewController: FORMViewController {
}

func updateButtonAction() {
self.dataSource.reloadWithDictionary(["first_name" : "Hodo",
self.dataSource.reload(with: ["first_name" : "Hodo",
"salary_type" : 1,
"hourly_pay_level" : 1,
"hourly_pay_premium_percent" : 10,
Expand Down
3 changes: 3 additions & 0 deletions Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@
};
1406BB911BEA521F00131623 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
};
1406BBA21BEA522900131623 = {
CreatedOnToolsVersion = 7.1;
Expand Down Expand Up @@ -2030,6 +2031,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.hyper.form.demo.Basic-Swift";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 2;
};
name = Debug;
Expand All @@ -2047,6 +2049,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.hyper.form.demo.Basic-Swift";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 2;
};
name = Release;
Expand Down