Skip to content

Commit

Permalink
Complete app
Browse files Browse the repository at this point in the history
  • Loading branch information
matteom committed Jun 12, 2017
1 parent 5a62ad7 commit 73f6343
Show file tree
Hide file tree
Showing 14 changed files with 667 additions and 62 deletions.
37 changes: 31 additions & 6 deletions TopQuestion.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,33 @@
objects = {

/* Begin PBXBuildFile section */
956FFD761EDC5B7B00F8CAC4 /* NetworkController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 956FFD751EDC5B7B00F8CAC4 /* NetworkController.swift */; };
95F3062D1ED70FF50029202E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F3062C1ED70FF50029202E /* AppDelegate.swift */; };
95F3062F1ED70FF50029202E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F3062E1ED70FF50029202E /* ViewController.swift */; };
95F3062F1ED70FF50029202E /* TopQuestionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F3062E1ED70FF50029202E /* TopQuestionViewController.swift */; };
95F306321ED70FF50029202E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 95F306301ED70FF50029202E /* Main.storyboard */; };
95F306341ED70FF50029202E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 95F306331ED70FF50029202E /* Assets.xcassets */; };
95F306371ED70FF50029202E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 95F306351ED70FF50029202E /* LaunchScreen.storyboard */; };
95F3063F1ED7124B0029202E /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F3063E1ED7124B0029202E /* User.swift */; };
95F306411ED712F30029202E /* Serialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F306401ED712F30029202E /* Serialization.swift */; };
95F306431ED715400029202E /* Question.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F306421ED715400029202E /* Question.swift */; };
95F306451ED718920029202E /* NetworkRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F306441ED718920029202E /* NetworkRequest.swift */; };
95F306471ED719E50029202E /* APIResources.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F306461ED719E50029202E /* APIResources.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
956FFD751EDC5B7B00F8CAC4 /* NetworkController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkController.swift; sourceTree = "<group>"; };
95F306291ED70FF50029202E /* TopQuestion.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TopQuestion.app; sourceTree = BUILT_PRODUCTS_DIR; };
95F3062C1ED70FF50029202E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
95F3062E1ED70FF50029202E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
95F3062E1ED70FF50029202E /* TopQuestionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopQuestionViewController.swift; sourceTree = "<group>"; };
95F306311ED70FF50029202E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
95F306331ED70FF50029202E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
95F306361ED70FF50029202E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
95F306381ED70FF60029202E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
95F3063E1ED7124B0029202E /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
95F306401ED712F30029202E /* Serialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Serialization.swift; sourceTree = "<group>"; };
95F306421ED715400029202E /* Question.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Question.swift; sourceTree = "<group>"; };
95F306441ED718920029202E /* NetworkRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkRequest.swift; sourceTree = "<group>"; };
95F306461ED719E50029202E /* APIResources.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APIResources.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -54,11 +66,17 @@
95F3062B1ED70FF50029202E /* TopQuestion */ = {
isa = PBXGroup;
children = (
95F3062C1ED70FF50029202E /* AppDelegate.swift */,
95F3062E1ED70FF50029202E /* ViewController.swift */,
95F306351ED70FF50029202E /* LaunchScreen.storyboard */,
95F306301ED70FF50029202E /* Main.storyboard */,
95F3062C1ED70FF50029202E /* AppDelegate.swift */,
95F3062E1ED70FF50029202E /* TopQuestionViewController.swift */,
95F3063E1ED7124B0029202E /* User.swift */,
95F306421ED715400029202E /* Question.swift */,
95F306401ED712F30029202E /* Serialization.swift */,
95F306441ED718920029202E /* NetworkRequest.swift */,
956FFD751EDC5B7B00F8CAC4 /* NetworkController.swift */,
95F306461ED719E50029202E /* APIResources.swift */,
95F306331ED70FF50029202E /* Assets.xcassets */,
95F306351ED70FF50029202E /* LaunchScreen.storyboard */,
95F306381ED70FF60029202E /* Info.plist */,
);
path = TopQuestion;
Expand Down Expand Up @@ -136,8 +154,14 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
95F3062F1ED70FF50029202E /* ViewController.swift in Sources */,
956FFD761EDC5B7B00F8CAC4 /* NetworkController.swift in Sources */,
95F306431ED715400029202E /* Question.swift in Sources */,
95F306471ED719E50029202E /* APIResources.swift in Sources */,
95F306411ED712F30029202E /* Serialization.swift in Sources */,
95F3062F1ED70FF50029202E /* TopQuestionViewController.swift in Sources */,
95F3062D1ED70FF50029202E /* AppDelegate.swift in Sources */,
95F306451ED718920029202E /* NetworkRequest.swift in Sources */,
95F3063F1ED7124B0029202E /* User.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -299,6 +323,7 @@
95F3063D1ED70FF60029202E /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "95F306281ED70FF50029202E"
BuildableName = "TopQuestion.app"
BlueprintName = "TopQuestion"
ReferencedContainer = "container:TopQuestion.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
Expand All @@ -13,6 +29,15 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "95F306281ED70FF50029202E"
BuildableName = "TopQuestion.app"
BlueprintName = "TopQuestion"
ReferencedContainer = "container:TopQuestion.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
Expand All @@ -26,6 +51,16 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "95F306281ED70FF50029202E"
BuildableName = "TopQuestion.app"
BlueprintName = "TopQuestion"
ReferencedContainer = "container:TopQuestion.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand All @@ -35,6 +70,16 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "95F306281ED70FF50029202E"
BuildableName = "TopQuestion.app"
BlueprintName = "TopQuestion"
ReferencedContainer = "container:TopQuestion.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
60 changes: 60 additions & 0 deletions TopQuestion/APIResources.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// APIResources.swift
// TopQuestion
//
// Created by Matteo Manferdini on 25/05/2017.
// Copyright © 2017 Pure Creek. All rights reserved.
//

import Foundation

struct ApiWrapper {
let items: [Serialization]
}

extension ApiWrapper {
private enum Keys: String, SerializationKey {
case items
}

init(serialization: Serialization) {
items = serialization.value(forKey: Keys.items) ?? []
}
}

protocol ApiResource {
associatedtype Model
var methodPath: String { get }
func makeModel(serialization: Serialization) -> Model
}

extension ApiResource {
var url: URL {
let baseUrl = "https://api.stackexchange.com/2.2"
let site = "site=stackoverflow"
let order = "order=desc"
let sorting = "sort=votes"
let tags = "tagged=ios"
let url = baseUrl + methodPath + "?" + order + "&" + sorting + "&" + tags + "&" + site
return URL(string: url)!
}

func makeModel(data: Data) -> [Model]? {
guard let json = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) else {
return nil
}
guard let jsonSerialization = json as? Serialization else {
return nil
}
let wrapper = ApiWrapper(serialization: jsonSerialization)
return wrapper.items.map(makeModel(serialization:))
}
}

struct QuestionsResource: ApiResource {
let methodPath = "/questions"

func makeModel(serialization: Serialization) -> Question {
return Question(serialization: serialization)
}
}
38 changes: 12 additions & 26 deletions TopQuestion/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,23 @@ import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().barTintColor = .electricViolet
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
return true
}
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
extension UIColor {
class var electricViolet: UIColor {
return UIColor(red: 144.0 / 255.0, green: 18.0 / 255.0, blue: 254.0 / 255.0, alpha: 1.0)
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
class var amethystSmoke: UIColor {
return UIColor(red: 169.0 / 255.0, green: 159.0 / 255.0, blue: 177.0 / 255.0, alpha: 1.0)
}


}

10 changes: 10 additions & 0 deletions TopQuestion/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down
Loading

0 comments on commit 73f6343

Please sign in to comment.