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 @@
7F996B2B2171D5D800FCC28F /* FoodPreferenceDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B2A2171D5D800FCC28F /* FoodPreferenceDelegate.swift */; };
7F996B2D2171EDD300FCC28F /* FoodPreferencesSectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B2C2171EDD300FCC28F /* FoodPreferencesSectionModel.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 */; };
B050E120215169230090CB79 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B050E11F215169230090CB79 /* AppDelegate.swift */; };
B050E127215169250090CB79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B050E126215169250090CB79 /* Assets.xcassets */; };
......@@ -121,6 +124,9 @@
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>"; };
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>"; };
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>"; };
......@@ -267,6 +273,16 @@
path = pubTrans;
sourceTree = "<group>";
};
7F996B36217269E100FCC28F /* JSON Parsing */ = {
isa = PBXGroup;
children = (
7F996B342172696500FCC28F /* SampleEventAdditFields.json */,
7FEF6E7721729D9100984BDB /* BeerTest.json */,
7F996B3721726ACD00FCC28F /* JSONParser.swift */,
);
path = "JSON Parsing";
sourceTree = "<group>";
};
B048377A21582C4500AFA689 /* Events */ = {
isa = PBXGroup;
children = (
......@@ -540,6 +556,7 @@
B050E1882151A4850090CB79 /* Settings Model */ = {
isa = PBXGroup;
children = (
7F996B36217269E100FCC28F /* JSON Parsing */,
B050E18B2151A54D0090CB79 /* SettingsCellModel.swift */,
B050E18F2151A6000090CB79 /* SettingsModel.swift */,
B050E1892151A4A80090CB79 /* SettingsAction.swift */,
......@@ -846,6 +863,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7FEF6E7821729D9200984BDB /* BeerTest.json in Resources */,
7FEF6E762172976100984BDB /* SampleEventAdditFields.json in Resources */,
B050E12A215169250090CB79 /* LaunchScreen.storyboard in Resources */,
B050E127215169250090CB79 /* Assets.xcassets in Resources */,
B0FE2F182155167F00F3D073 /* Dienstverschiebungsgesuch.pdf in Resources */,
......@@ -951,6 +970,7 @@
B0AF91302157B26C008F3B80 /* HTTPTask.swift in Sources */,
B07A8A022152384F003CC2D8 /* InfoItemModel.swift in Sources */,
7F996B26217168CD00FCC28F /* FoodPreferenceCellType.swift in Sources */,
7F996B3821726ACD00FCC28F /* JSONParser.swift in Sources */,
B0FE2EFC2154179600F3D073 /* JobsViewController.swift in Sources */,
B050E17321517A050090CB79 /* AmivMicroAppType.swift in Sources */,
B0AF91402157CF50008F3B80 /* AMIVApiEvents.swift in Sources */,
......
......@@ -11,13 +11,11 @@ import UIKit
public class FoodPreferenceModel{
public private(set) var sectionModels: [FoodPreferenceSectionModel]
// MARK: - Initializers
public init(sectionModels: [FoodPreferenceSectionModel]) {
self.sectionModels = sectionModels
}
//TODO Add Variables/Models
}
extension FoodPreferenceModel{
......@@ -26,13 +24,16 @@ extension FoodPreferenceModel{
return FoodPreferenceModel(sectionModels: sections)
}
//TODO Make Dynamic
//Parse JSON into Table View
public static func createFoodPreferenceSection() -> FoodPreferenceSectionModel {
let vegetarisch = FoodPreferencesCellModel(text: "vegetarisch", action: .changeFoodPreference, cellType: .normal)
let Nichts = FoodPreferencesCellModel(text: "Keine Vorlieben", action: .changeFoodPreference, cellType: .normal)
let Other = FoodPreferencesCellModel(text: "Other Food", action: .changeFoodPreference, cellType: .normal)
return FoodPreferenceSectionModel(headerText: "Your Choice", footerText: "FooterText", cellModels: [vegetarisch, Nichts, Other])
let jsonParser = JSONParser()
var FoodCellModel = [FoodPreferencesCellModel]()
jsonParser.parseJSONData(Filename: "SampleEventAdditFields")
jsonParser.FoodTypes.forEach { (Food) in
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 @@
import Foundation
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 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 {
debugPrint("failed to get JSON Path")
return}
......@@ -20,21 +37,32 @@ public class JSONParser {
let jsonData = content.data(using: .utf8)!
let decoder = JSONDecoder()
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 {
print("Error info: \(error)")
}
}
}
public func CountPropertiesElements(){
}
//Definiere JSON Dictionarys als structs, nach Vorlage SampleEventAdditFields.json
extension JSONParser{
struct Root : Decodable {
public struct Root : Decodable {
private enum CodingKeys : String, CodingKey { case properties = "properties" }
let properties : PropertiesStruct
}
}
struct PropertiesStruct : Decodable {
public struct PropertiesStruct : Decodable {
private enum CodingKeys : String, CodingKey {
case sbbAbo = "SBB_Abo"
case Food = "Food"
......@@ -43,27 +71,29 @@ struct PropertiesStruct : Decodable {
let sbbAbo : sbbAboStruct
let Food : FoodStruct
let SFR : SFRStruct
}
}
struct sbbAboStruct : Decodable {
public struct sbbAboStruct : Decodable {
private enum CodingKeys : String, CodingKey {
case type = "type"
case Enum = "enum"
}
let type : String
let Enum : [String]
}
struct FoodStruct : Decodable {
}
public struct FoodStruct : Decodable {
private enum CodingKeys : String, CodingKey {
case type = "type"
case Enum = "enum"
}
let type : String
let Enum : [String]
}
struct SFRStruct : Decodable {
}
public struct SFRStruct : Decodable {
private enum CodingKeys : String, CodingKey {
case type = "type"
}
let type : String
}
}
......@@ -13,11 +13,12 @@
"Food":
{
"type":"string",
"enum":["Omnivor","Vegi","Vegan","Other"]
"enum":["Omnivor","Vegi","Vegan","Other","Created With JSON"]
},
"Special Food Requirements":
{
"type":"string"
"type":"string",
}
},
"required":["SBB_Abo","Food"]
......
......@@ -65,7 +65,6 @@ extension EventsNavigator: EventsViewControllerDelegate {
}
}
extension EventsNavigator: GenericInfoViewControllerDelegate {
public func buttonTapped(_ viewController: GenericInfoViewController) {
......
......@@ -26,7 +26,7 @@ class CustomTableViewCell: UITableViewCell {
let Label = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 20))
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.placeholder = "Enter text here"
sampleTextField.font = UIFont.systemFont(ofSize: 15)
......@@ -37,15 +37,14 @@ class CustomTableViewCell: UITableViewCell {
sampleTextField.clearButtonMode = UITextField.ViewMode.whileEditing;
sampleTextField.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center
contentView.addSubview(sampleTextField)
/*
sampleTextField.widthAnchor.constraint(equalToConstant: 400).isActive = true
sampleTextField.heightAnchor.constraint(equalToConstant: 40).isActive = true
debugPrint(self.contentView.centerXAnchor)
sampleTextField.centerXAnchor.constraint(equalTo: self.contentView.centerXAnchor).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 {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationItem.largeTitleDisplayMode = .always
}
}
......@@ -73,7 +74,6 @@ extension FoodPreferenceViewController {
return cell
}
public override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cellModel = self.model.sectionModels[indexPath.section].cellModels[indexPath.row]
let cell = tableView.cellForRow(at: indexPath)
......
......@@ -18,15 +18,15 @@ public class SettingsViewController: UITableViewController {
private var model: SettingsModel
private var CustomIdentifier = "customIdentifier"
public var delegate: SettingsViewControllerDelegate?
// MARK: - Initializers
public init(model: SettingsModel) {
self.model = model
super.init(style: .grouped)
self.title = "Settings"
self.tableView.register(CustomTableViewCell.self, forCellReuseIdentifier: CustomIdentifier)
}
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