Commit bdd5a1b3 authored by gabrieso's avatar gabrieso
Browse files

JSON Parser populates FoodTable View but isn't dynamic

parent f4ec3857
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
7F996B2B2171D5D800FCC28F /* FoodPreferenceDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B2A2171D5D800FCC28F /* FoodPreferenceDelegate.swift */; }; 7F996B2B2171D5D800FCC28F /* FoodPreferenceDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B2A2171D5D800FCC28F /* FoodPreferenceDelegate.swift */; };
7F996B2D2171EDD300FCC28F /* FoodPreferencesSectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B2C2171EDD300FCC28F /* FoodPreferencesSectionModel.swift */; }; 7F996B2D2171EDD300FCC28F /* FoodPreferencesSectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B2C2171EDD300FCC28F /* FoodPreferencesSectionModel.swift */; };
7F996B3321723D5B00FCC28F /* CustomTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B3221723D5B00FCC28F /* CustomTableViewCell.swift */; }; 7F996B3321723D5B00FCC28F /* CustomTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B3221723D5B00FCC28F /* CustomTableViewCell.swift */; };
7F996B3821726ACD00FCC28F /* JSONParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B3721726ACD00FCC28F /* JSONParser.swift */; };
7FEF6E762172976100984BDB /* SampleEventAdditFields.json in Resources */ = {isa = PBXBuildFile; fileRef = 7F996B342172696500FCC28F /* SampleEventAdditFields.json */; };
7FEF6E7821729D9200984BDB /* BeerTest.json in Resources */ = {isa = PBXBuildFile; fileRef = 7FEF6E7721729D9100984BDB /* BeerTest.json */; };
B048377E21582D4E00AFA689 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B048377D21582D4E00AFA689 /* String+Extension.swift */; }; B048377E21582D4E00AFA689 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B048377D21582D4E00AFA689 /* String+Extension.swift */; };
B050E120215169230090CB79 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B050E11F215169230090CB79 /* AppDelegate.swift */; }; B050E120215169230090CB79 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B050E11F215169230090CB79 /* AppDelegate.swift */; };
B050E127215169250090CB79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B050E126215169250090CB79 /* Assets.xcassets */; }; B050E127215169250090CB79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B050E126215169250090CB79 /* Assets.xcassets */; };
...@@ -121,6 +124,9 @@ ...@@ -121,6 +124,9 @@
7F996B2A2171D5D800FCC28F /* FoodPreferenceDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodPreferenceDelegate.swift; sourceTree = "<group>"; }; 7F996B2A2171D5D800FCC28F /* FoodPreferenceDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodPreferenceDelegate.swift; sourceTree = "<group>"; };
7F996B2C2171EDD300FCC28F /* FoodPreferencesSectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodPreferencesSectionModel.swift; sourceTree = "<group>"; }; 7F996B2C2171EDD300FCC28F /* FoodPreferencesSectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodPreferencesSectionModel.swift; sourceTree = "<group>"; };
7F996B3221723D5B00FCC28F /* CustomTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTableViewCell.swift; sourceTree = "<group>"; }; 7F996B3221723D5B00FCC28F /* CustomTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTableViewCell.swift; sourceTree = "<group>"; };
7F996B342172696500FCC28F /* SampleEventAdditFields.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SampleEventAdditFields.json; sourceTree = "<group>"; };
7F996B3721726ACD00FCC28F /* JSONParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONParser.swift; sourceTree = "<group>"; };
7FEF6E7721729D9100984BDB /* BeerTest.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = BeerTest.json; sourceTree = "<group>"; };
B048377D21582D4E00AFA689 /* String+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; }; B048377D21582D4E00AFA689 /* String+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; };
B050E11C215169230090CB79 /* Amiv.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Amiv.app; sourceTree = BUILT_PRODUCTS_DIR; }; B050E11C215169230090CB79 /* Amiv.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Amiv.app; sourceTree = BUILT_PRODUCTS_DIR; };
B050E11F215169230090CB79 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; B050E11F215169230090CB79 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
...@@ -267,6 +273,16 @@ ...@@ -267,6 +273,16 @@
path = pubTrans; path = pubTrans;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
7F996B36217269E100FCC28F /* JSON Parsing */ = {
isa = PBXGroup;
children = (
7F996B342172696500FCC28F /* SampleEventAdditFields.json */,
7FEF6E7721729D9100984BDB /* BeerTest.json */,
7F996B3721726ACD00FCC28F /* JSONParser.swift */,
);
path = "JSON Parsing";
sourceTree = "<group>";
};
B048377A21582C4500AFA689 /* Events */ = { B048377A21582C4500AFA689 /* Events */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -540,6 +556,7 @@ ...@@ -540,6 +556,7 @@
B050E1882151A4850090CB79 /* Settings Model */ = { B050E1882151A4850090CB79 /* Settings Model */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
7F996B36217269E100FCC28F /* JSON Parsing */,
B050E18B2151A54D0090CB79 /* SettingsCellModel.swift */, B050E18B2151A54D0090CB79 /* SettingsCellModel.swift */,
B050E18F2151A6000090CB79 /* SettingsModel.swift */, B050E18F2151A6000090CB79 /* SettingsModel.swift */,
B050E1892151A4A80090CB79 /* SettingsAction.swift */, B050E1892151A4A80090CB79 /* SettingsAction.swift */,
...@@ -846,6 +863,8 @@ ...@@ -846,6 +863,8 @@
isa = PBXResourcesBuildPhase; isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
7FEF6E7821729D9200984BDB /* BeerTest.json in Resources */,
7FEF6E762172976100984BDB /* SampleEventAdditFields.json in Resources */,
B050E12A215169250090CB79 /* LaunchScreen.storyboard in Resources */, B050E12A215169250090CB79 /* LaunchScreen.storyboard in Resources */,
B050E127215169250090CB79 /* Assets.xcassets in Resources */, B050E127215169250090CB79 /* Assets.xcassets in Resources */,
B0FE2F182155167F00F3D073 /* Dienstverschiebungsgesuch.pdf in Resources */, B0FE2F182155167F00F3D073 /* Dienstverschiebungsgesuch.pdf in Resources */,
...@@ -951,6 +970,7 @@ ...@@ -951,6 +970,7 @@
B0AF91302157B26C008F3B80 /* HTTPTask.swift in Sources */, B0AF91302157B26C008F3B80 /* HTTPTask.swift in Sources */,
B07A8A022152384F003CC2D8 /* InfoItemModel.swift in Sources */, B07A8A022152384F003CC2D8 /* InfoItemModel.swift in Sources */,
7F996B26217168CD00FCC28F /* FoodPreferenceCellType.swift in Sources */, 7F996B26217168CD00FCC28F /* FoodPreferenceCellType.swift in Sources */,
7F996B3821726ACD00FCC28F /* JSONParser.swift in Sources */,
B0FE2EFC2154179600F3D073 /* JobsViewController.swift in Sources */, B0FE2EFC2154179600F3D073 /* JobsViewController.swift in Sources */,
B050E17321517A050090CB79 /* AmivMicroAppType.swift in Sources */, B050E17321517A050090CB79 /* AmivMicroAppType.swift in Sources */,
B0AF91402157CF50008F3B80 /* AMIVApiEvents.swift in Sources */, B0AF91402157CF50008F3B80 /* AMIVApiEvents.swift in Sources */,
......
...@@ -11,13 +11,11 @@ import UIKit ...@@ -11,13 +11,11 @@ import UIKit
public class FoodPreferenceModel{ public class FoodPreferenceModel{
public private(set) var sectionModels: [FoodPreferenceSectionModel] public private(set) var sectionModels: [FoodPreferenceSectionModel]
// MARK: - Initializers // MARK: - Initializers
public init(sectionModels: [FoodPreferenceSectionModel]) { public init(sectionModels: [FoodPreferenceSectionModel]) {
self.sectionModels = sectionModels self.sectionModels = sectionModels
} }
//TODO Add Variables/Models
} }
extension FoodPreferenceModel{ extension FoodPreferenceModel{
...@@ -26,13 +24,16 @@ extension FoodPreferenceModel{ ...@@ -26,13 +24,16 @@ extension FoodPreferenceModel{
return FoodPreferenceModel(sectionModels: sections) return FoodPreferenceModel(sectionModels: sections)
} }
//TODO Make Dynamic //Parse JSON into Table View
public static func createFoodPreferenceSection() -> FoodPreferenceSectionModel { public static func createFoodPreferenceSection() -> FoodPreferenceSectionModel {
let vegetarisch = FoodPreferencesCellModel(text: "vegetarisch", action: .changeFoodPreference, cellType: .normal) let jsonParser = JSONParser()
let Nichts = FoodPreferencesCellModel(text: "Keine Vorlieben", action: .changeFoodPreference, cellType: .normal) var FoodCellModel = [FoodPreferencesCellModel]()
let Other = FoodPreferencesCellModel(text: "Other Food", action: .changeFoodPreference, cellType: .normal) jsonParser.parseJSONData(Filename: "SampleEventAdditFields")
jsonParser.FoodTypes.forEach { (Food) in
return FoodPreferenceSectionModel(headerText: "Your Choice", footerText: "FooterText", cellModels: [vegetarisch, Nichts, Other]) let food = FoodPreferencesCellModel(text: Food, action: .changeFoodPreference, cellType: .normal)
} FoodCellModel.append(food)
}
return FoodPreferenceSectionModel(headerText: "Your Choice", footerText: "FooterText", cellModels: FoodCellModel)
}
} }
...@@ -9,9 +9,26 @@ ...@@ -9,9 +9,26 @@
import Foundation import Foundation
import UIKit import UIKit
public class AdditField{
public static let ARRAY : Int = 0;
public static let BOOLEAN : Int = 1;
public static let INTEGER : Int = 2;
public static let NULL : Int = 3;
public static let NUMBER : Int = 4;
public static let OBJECT : Int = 5;
public static let STRING : Int = 6;
}
public class JSONParser { public class JSONParser {
public func getJSONData(Filename: String){ public var SbbAbos : [String]!
public var FoodTypes : [String]!
public var SFR : String!
public func parseJSONData(Filename: String) {
guard let path = Bundle.main.path(forResource: Filename, ofType: "json") else { guard let path = Bundle.main.path(forResource: Filename, ofType: "json") else {
debugPrint("failed to get JSON Path") debugPrint("failed to get JSON Path")
return} return}
...@@ -20,50 +37,63 @@ public class JSONParser { ...@@ -20,50 +37,63 @@ public class JSONParser {
let jsonData = content.data(using: .utf8)! let jsonData = content.data(using: .utf8)!
let decoder = JSONDecoder() let decoder = JSONDecoder()
let result = try decoder.decode(Root.self, from: jsonData) let result = try decoder.decode(Root.self, from: jsonData)
dump(result) debugPrint("successfully parsed JSON File")
//Copy Results to String-Arrays and Strings
dump(result.properties)
SbbAbos = result.properties.sbbAbo.Enum
FoodTypes = result.properties.Food.Enum
SFR = result.properties.SFR.type
} catch { } catch {
print("Error info: \(error)") print("Error info: \(error)")
} }
} }
} }
//Definiere JSON Dictionarys als structs, nach Vorlage SampleEventAdditFields.json public func CountPropertiesElements(){
struct Root : Decodable {
private enum CodingKeys : String, CodingKey { case properties = "properties" }
let properties : PropertiesStruct
} }
struct PropertiesStruct : Decodable { //Definiere JSON Dictionarys als structs, nach Vorlage SampleEventAdditFields.json
private enum CodingKeys : String, CodingKey { extension JSONParser{
case sbbAbo = "SBB_Abo"
case Food = "Food" public struct Root : Decodable {
case SFR = "Special Food Requirements" private enum CodingKeys : String, CodingKey { case properties = "properties" }
let properties : PropertiesStruct
} }
let sbbAbo : sbbAboStruct
let Food : FoodStruct public struct PropertiesStruct : Decodable {
let SFR : SFRStruct private enum CodingKeys : String, CodingKey {
} case sbbAbo = "SBB_Abo"
case Food = "Food"
struct sbbAboStruct : Decodable { case SFR = "Special Food Requirements"
private enum CodingKeys : String, CodingKey { }
case type = "type" let sbbAbo : sbbAboStruct
case Enum = "enum" let Food : FoodStruct
let SFR : SFRStruct
} }
let type : String
let Enum : [String] public struct sbbAboStruct : Decodable {
} private enum CodingKeys : String, CodingKey {
struct FoodStruct : Decodable { case type = "type"
private enum CodingKeys : String, CodingKey { case Enum = "enum"
case type = "type" }
case Enum = "enum" let type : String
let Enum : [String]
} }
let type : String public struct FoodStruct : Decodable {
let Enum : [String] private enum CodingKeys : String, CodingKey {
} case type = "type"
struct SFRStruct : Decodable { case Enum = "enum"
private enum CodingKeys : String, CodingKey { }
case type = "type" let type : String
let Enum : [String]
}
public struct SFRStruct : Decodable {
private enum CodingKeys : String, CodingKey {
case type = "type"
}
let type : String
} }
let type : String
} }
...@@ -13,11 +13,12 @@ ...@@ -13,11 +13,12 @@
"Food": "Food":
{ {
"type":"string", "type":"string",
"enum":["Omnivor","Vegi","Vegan","Other"] "enum":["Omnivor","Vegi","Vegan","Other","Created With JSON"]
}, },
"Special Food Requirements": "Special Food Requirements":
{ {
"type":"string" "type":"string",
} }
}, },
"required":["SBB_Abo","Food"] "required":["SBB_Abo","Food"]
......
...@@ -65,7 +65,6 @@ extension EventsNavigator: EventsViewControllerDelegate { ...@@ -65,7 +65,6 @@ extension EventsNavigator: EventsViewControllerDelegate {
} }
} }
extension EventsNavigator: GenericInfoViewControllerDelegate { extension EventsNavigator: GenericInfoViewControllerDelegate {
public func buttonTapped(_ viewController: GenericInfoViewController) { public func buttonTapped(_ viewController: GenericInfoViewController) {
......
...@@ -26,7 +26,7 @@ class CustomTableViewCell: UITableViewCell { ...@@ -26,7 +26,7 @@ class CustomTableViewCell: UITableViewCell {
let Label = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 20)) let Label = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 20))
Label.text = "Food Requierement" Label.text = "Food Requierement"
let sampleTextField = UITextField(frame: CGRect(x: 0, y: 0, width: 300, height: 40)) let sampleTextField = UITextField(frame: CGRect(x: 0, y: 0, width: 500, height: 40))
sampleTextField.textAlignment = .center sampleTextField.textAlignment = .center
sampleTextField.placeholder = "Enter text here" sampleTextField.placeholder = "Enter text here"
sampleTextField.font = UIFont.systemFont(ofSize: 15) sampleTextField.font = UIFont.systemFont(ofSize: 15)
...@@ -37,15 +37,14 @@ class CustomTableViewCell: UITableViewCell { ...@@ -37,15 +37,14 @@ class CustomTableViewCell: UITableViewCell {
sampleTextField.clearButtonMode = UITextField.ViewMode.whileEditing; sampleTextField.clearButtonMode = UITextField.ViewMode.whileEditing;
sampleTextField.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center sampleTextField.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center
contentView.addSubview(sampleTextField) contentView.addSubview(sampleTextField)
/*
sampleTextField.widthAnchor.constraint(equalToConstant: 400).isActive = true sampleTextField.widthAnchor.constraint(equalToConstant: 400).isActive = true
sampleTextField.heightAnchor.constraint(equalToConstant: 40).isActive = true sampleTextField.heightAnchor.constraint(equalToConstant: 40).isActive = true
debugPrint(self.contentView.centerXAnchor)
sampleTextField.centerXAnchor.constraint(equalTo: self.contentView.centerXAnchor).isActive = true sampleTextField.centerXAnchor.constraint(equalTo: self.contentView.centerXAnchor).isActive = true
sampleTextField.centerYAnchor.constraint(equalTo: self.contentView.centerYAnchor).isActive = true sampleTextField.centerYAnchor.constraint(equalTo: self.contentView.centerYAnchor).isActive = true
*/
} }
} }
//
// CustomFoodCellTableViewCell.swift
// Amiv
//
// Created by Gabriel Sonderegger on 13.10.18.
// Copyright © 2018 Amiv an der ETH. All rights reserved.
//
import UIKit
class CustomFoodCell: UITableViewCell {
var FoodChoiceLabel :UILabel!
var TextField : UITextField!
override func awakeFromNib() {
super.awakeFromNib()
initalizeLabel()
initializeTextField()
}
private func initalizeLabel(){
FoodChoiceLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 60))
FoodChoiceLabel.text = "I'am a test label"
contentView.addSubview(FoodChoiceLabel)
}
private func initializeTextField(){
TextField = UITextField(frame: CGRect(x: 0, y: 0, width: 200, height: 60))
contentView.addSubview(TextField)
}
}
...@@ -32,6 +32,7 @@ class FoodPreferenceViewController: UITableViewController { ...@@ -32,6 +32,7 @@ class FoodPreferenceViewController: UITableViewController {
super.viewWillAppear(animated) super.viewWillAppear(animated)
self.navigationController?.navigationBar.prefersLargeTitles = true self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationItem.largeTitleDisplayMode = .always self.navigationItem.largeTitleDisplayMode = .always
} }
} }
...@@ -73,7 +74,6 @@ extension FoodPreferenceViewController { ...@@ -73,7 +74,6 @@ extension FoodPreferenceViewController {
return cell return cell
} }
public override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { public override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cellModel = self.model.sectionModels[indexPath.section].cellModels[indexPath.row] let cellModel = self.model.sectionModels[indexPath.section].cellModels[indexPath.row]
let cell = tableView.cellForRow(at: indexPath) let cell = tableView.cellForRow(at: indexPath)
......
...@@ -18,15 +18,15 @@ public class SettingsViewController: UITableViewController { ...@@ -18,15 +18,15 @@ public class SettingsViewController: UITableViewController {
private var model: SettingsModel private var model: SettingsModel
private var CustomIdentifier = "customIdentifier" private var CustomIdentifier = "customIdentifier"
public var delegate: SettingsViewControllerDelegate? public var delegate: SettingsViewControllerDelegate?
// MARK: - Initializers // MARK: - Initializers
public init(model: SettingsModel) { public init(model: SettingsModel) {
self.model = model self.model = model
super.init(style: .grouped) super.init(style: .grouped)
self.title = "Settings" self.title = "Settings"
self.tableView.register(CustomTableViewCell.self, forCellReuseIdentifier: CustomIdentifier) self.tableView.register(CustomTableViewCell.self, forCellReuseIdentifier: CustomIdentifier)
} }
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment