Skip to content

Commit

Permalink
Reading and parsing questions
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamSliwakowski committed Apr 22, 2016
1 parent c21b8e7 commit ce3208e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
17 changes: 9 additions & 8 deletions Succotash/Succotash.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
objects = {

/* Begin PBXBuildFile section */
0CBE7D8E1CCAB0630007E48A /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 0CBE7D801CCAB0630007E48A /* Info.plist */; };
0CBE7D8F1CCAB0630007E48A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0CBE7D821CCAB0630007E48A /* LaunchScreen.storyboard */; };
0CBE7D901CCAB0630007E48A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0CBE7D851CCAB0630007E48A /* Assets.xcassets */; };
0CBE7D911CCAB0630007E48A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CBE7D881CCAB0630007E48A /* AppDelegate.swift */; };
0CBE7D921CCAB0630007E48A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0CBE7D8B1CCAB0630007E48A /* Main.storyboard */; };
0CBE7D941CCAB2EE0007E48A /* questions.json in Resources */ = {isa = PBXBuildFile; fileRef = 0CBE7D931CCAB2EE0007E48A /* questions.json */; };
0CBE7D961CCAB43F0007E48A /* Question.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CBE7D951CCAB43F0007E48A /* Question.swift */; };
0CBE7D981CCAB44E0007E48A /* QuestionsBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CBE7D971CCAB44E0007E48A /* QuestionsBlock.swift */; };
0CBE7D9A1CCAB66C0007E48A /* JSONFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CBE7D991CCAB66C0007E48A /* JSONFile.swift */; };
0CBE7D9A1CCAB66C0007E48A /* JSONExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CBE7D991CCAB66C0007E48A /* JSONExtension.swift */; };
0CBE7D9E1CCAB6FA0007E48A /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0CBE7D9C1CCAB6FA0007E48A /* SwiftyJSON.framework */; };
0CBE7D9F1CCAB6FA0007E48A /* SwiftyTimer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0CBE7D9D1CCAB6FA0007E48A /* SwiftyTimer.framework */; };
/* End PBXBuildFile section */
Expand All @@ -30,7 +29,7 @@
0CBE7D931CCAB2EE0007E48A /* questions.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = questions.json; sourceTree = "<group>"; };
0CBE7D951CCAB43F0007E48A /* Question.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Question.swift; sourceTree = "<group>"; };
0CBE7D971CCAB44E0007E48A /* QuestionsBlock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuestionsBlock.swift; sourceTree = "<group>"; };
0CBE7D991CCAB66C0007E48A /* JSONFile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONFile.swift; sourceTree = "<group>"; };
0CBE7D991CCAB66C0007E48A /* JSONExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONExtension.swift; sourceTree = "<group>"; };
0CBE7D9C1CCAB6FA0007E48A /* SwiftyJSON.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftyJSON.framework; path = ../Carthage/Build/iOS/SwiftyJSON.framework; sourceTree = "<group>"; };
0CBE7D9D1CCAB6FA0007E48A /* SwiftyTimer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftyTimer.framework; path = ../Carthage/Build/iOS/SwiftyTimer.framework; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -101,7 +100,7 @@
isa = PBXGroup;
children = (
0CBE7D881CCAB0630007E48A /* AppDelegate.swift */,
0CBE7D991CCAB66C0007E48A /* JSONFile.swift */,
0CBE7D991CCAB66C0007E48A /* JSONExtension.swift */,
);
path = Logic;
sourceTree = "<group>";
Expand Down Expand Up @@ -156,7 +155,7 @@
0CBE7D601CCAAE6C0007E48A /* Sources */,
0CBE7D611CCAAE6C0007E48A /* Frameworks */,
0CBE7D621CCAAE6C0007E48A /* Resources */,
0CBE7D9B1CCAB6990007E48A /* ShellScript */,
0CBE7D9B1CCAB6990007E48A /* Carthage */,
);
buildRules = (
);
Expand Down Expand Up @@ -206,7 +205,6 @@
buildActionMask = 2147483647;
files = (
0CBE7D941CCAB2EE0007E48A /* questions.json in Resources */,
0CBE7D8E1CCAB0630007E48A /* Info.plist in Resources */,
0CBE7D901CCAB0630007E48A /* Assets.xcassets in Resources */,
0CBE7D8F1CCAB0630007E48A /* LaunchScreen.storyboard in Resources */,
0CBE7D921CCAB0630007E48A /* Main.storyboard in Resources */,
Expand All @@ -216,7 +214,7 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
0CBE7D9B1CCAB6990007E48A /* ShellScript */ = {
0CBE7D9B1CCAB6990007E48A /* Carthage */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -225,6 +223,7 @@
"$(SRCROOT)/Carthage/Build/iOS/SwiftyJSON.framework",
"$(SRCROOT)/Carthage/Build/iOS/SwiftyTimer.framework",
);
name = Carthage;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -241,7 +240,7 @@
0CBE7D981CCAB44E0007E48A /* QuestionsBlock.swift in Sources */,
0CBE7D911CCAB0630007E48A /* AppDelegate.swift in Sources */,
0CBE7D961CCAB43F0007E48A /* Question.swift in Sources */,
0CBE7D9A1CCAB66C0007E48A /* JSONFile.swift in Sources */,
0CBE7D9A1CCAB66C0007E48A /* JSONExtension.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -354,6 +353,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/Carthage/Build/iOS";
INFOPLIST_FILE = Succotash/Base.lproj/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.sliwakowski.Succotash;
Expand All @@ -365,6 +365,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/Carthage/Build/iOS";
INFOPLIST_FILE = Succotash/Base.lproj/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.sliwakowski.Succotash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
{
"idiom" : "universal",
"filename" : "question3.png",
"scale" : "2x"
},
{
Expand Down
6 changes: 3 additions & 3 deletions Succotash/Succotash/Content/questions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"blocks": [
{
"mandatory": true,
"is_mandatory": true,
"questions": [
{
"question": "Could you sleep well last night?",
Expand All @@ -18,7 +18,7 @@
]
},
{
"mandatory": true,
"is_mandatory": true,
"questions": [
{
"question": "Do you currently have less interesting in things you usually enjoy?",
Expand All @@ -35,7 +35,7 @@
]
},
{
"mandatory": false,
"is_mandatory": false,
"questions": [
{
"question": "Do feel exhausted by daily activities much quicker than usual?",
Expand Down
18 changes: 18 additions & 0 deletions Succotash/Succotash/Logic/JSONExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// JSONExtension.swift
// Succotash
//
// Created by Adam Śliwakowski on 22.04.2016.
// Copyright © 2016 sliwakowski. All rights reserved.
//

import Foundation
import SwiftyJSON

extension JSON {
static func read(filename: String) -> JSON {
guard let path = NSBundle.mainBundle().pathForResource(filename, ofType: "json") else { return JSON("") }
let jsonData = NSData(contentsOfFile:path)
return JSON(data: jsonData!)
}
}
7 changes: 7 additions & 0 deletions Succotash/Succotash/Model/Question.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
// Copyright © 2016 sliwakowski. All rights reserved.
//

import SwiftyJSON

struct Question {
var text: String
var image: String

init(json: JSON) {
text = json["question"].stringValue
image = json["image"].stringValue
}
}
7 changes: 7 additions & 0 deletions Succotash/Succotash/Model/QuestionsBlock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
// Copyright © 2016 sliwakowski. All rights reserved.
//

import SwiftyJSON

struct QuestionsBlock {
var isMandatory: Bool
var isFinished: Bool = false
var questions: [Question]

init(json: JSON) {
isMandatory = json["is_mandatory"].boolValue
questions = json["questions"].arrayValue.map { Question(json: $0) }
}
}

0 comments on commit ce3208e

Please sign in to comment.