Skip to content

Commit

Permalink
Style Guide compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
rcritz committed Jan 17, 2021
1 parent 76067f3 commit ab04445
Show file tree
Hide file tree
Showing 28 changed files with 132 additions and 91 deletions.
Expand Up @@ -29,7 +29,6 @@
import Vapor

struct UsersController: RouteCollection {

func boot(routes: RoutesBuilder) throws {
let usersRoute = routes.grouped("api", "users")
usersRoute.get(use: getAllHandler)
Expand Down
Expand Up @@ -29,7 +29,6 @@
import Vapor

struct WebsiteController: RouteCollection {

func boot(routes: RoutesBuilder) throws {
routes.get(use: indexHandler)
routes.get("acronyms", ":acronymID", use: acronymHandler)
Expand Down Expand Up @@ -114,7 +113,7 @@ struct WebsiteController: RouteCollection {
guard let id = acronym.id else {
return req.eventLoop.future(error: Abort(.internalServerError))
}
var categorySaves = [EventLoopFuture<Void>]()
var categorySaves: [EventLoopFuture<Void>] = []
for category in data.categories ?? [] {
categorySaves.append(Category.addCategory(category, to: acronym, on: req))
}
Expand Down Expand Up @@ -156,7 +155,7 @@ struct WebsiteController: RouteCollection {
let categoriesToAdd = newSet.subtracting(existingSet)
let categoriesToRemove = existingSet.subtracting(newSet)

var categoryResults = [EventLoopFuture<Void>]()
var categoryResults: [EventLoopFuture<Void>] = []
for newCategory in categoriesToAdd {
categoryResults.append(Category.addCategory(newCategory, to: acronym, on: req))
}
Expand Down
Expand Up @@ -52,7 +52,7 @@ extension XCTApplicationTester {
body: ByteBufferAllocator().buffer(capacity: 0)
)
request.headers.basicAuthorization = .init(username: user.username, password: "password")
let response = try self.performTest(request: request)
let response = try performTest(request: request)
return try response.content.decode(Token.self)
}

Expand Down Expand Up @@ -85,14 +85,14 @@ extension XCTApplicationTester {
userToLogin = User(name: "Admin", username: "admin", password: "password")
}

let token = try self.login(user: userToLogin)
let token = try login(user: userToLogin)
request.headers.bearerAuthorization = .init(token: token.value)
}

try beforeRequest(&request)

do {
let response = try self.performTest(request: request)
let response = try performTest(request: request)
try afterResponse(response)
} catch {
XCTFail("\(error)", file: (file), line: line)
Expand Down
Expand Up @@ -171,7 +171,7 @@
isa = PBXNativeTarget;
buildConfigurationList = D2A5F2121F4A9144005CD714 /* Build configuration list for PBXNativeTarget "TILiOS" */;
buildPhases = (
2323AF6D24B7811400D2E1B6 /* ShellScript */,
2323AF6D24B7811400D2E1B6 /* SwiftLint */,
D2A5F1FC1F4A9144005CD714 /* Sources */,
D2A5F1FD1F4A9144005CD714 /* Frameworks */,
D2A5F1FE1F4A9144005CD714 /* Resources */,
Expand All @@ -193,7 +193,7 @@
attributes = {
LastSwiftUpdateCheck = 0900;
LastUpgradeCheck = 1230;
ORGANIZATIONNAME = Razeware;
ORGANIZATIONNAME = "Ray Wenderlich";
TargetAttributes = {
D2A5F1FF1F4A9144005CD714 = {
CreatedOnToolsVersion = 9.0;
Expand Down Expand Up @@ -234,7 +234,7 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
2323AF6D24B7811400D2E1B6 /* ShellScript */ = {
2323AF6D24B7811400D2E1B6 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -243,13 +243,14 @@
);
inputPaths = (
);
name = SwiftLint;
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if [ -f ~/com.raywenderlich.swiftlint.yml ]; then\n if which swiftlint >/dev/null; then\n swiftlint --config ~/com.raywenderlich.swiftlint.yml\n fi\nfi\n";
shellScript = "if [ -f ~/com.raywenderlich.swiftlint.yml ]; then\n if which swiftlint >/dev/null; then\n swiftlint --no-cache --config ~/com.raywenderlich.swiftlint.yml\n fi\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -421,7 +422,7 @@
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "$(SRCROOT)/TILiOS/Project Files/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.razeware.TILiOS;
PRODUCT_BUNDLE_IDENTIFIER = com.raywenderlich.TILiOS;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = 1;
Expand All @@ -436,7 +437,7 @@
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "$(SRCROOT)/TILiOS/Project Files/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.razeware.TILiOS;
PRODUCT_BUNDLE_IDENTIFIER = com.raywenderlich.TILiOS;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 1;
};
Expand Down
Expand Up @@ -36,7 +36,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
if Auth().token == nil {
let rootController = UIStoryboard(name: "Login", bundle: Bundle.main)
.instantiateViewController(withIdentifier: "LoginNavigation")
self.window?.rootViewController = rootController
window?.rootViewController = rootController
}
return true
}
Expand Down
Expand Up @@ -20,6 +20,11 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -34,11 +39,6 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -15,34 +13,34 @@
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="428" height="926"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="rwdevcon-bg" translatesAutoresizingMaskIntoConstraints="NO" id="thr-yb-z25">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="428" height="926"/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="rw-logo" translatesAutoresizingMaskIntoConstraints="NO" id="skm-4Q-SEq">
<rect key="frame" x="20" y="166" width="335" height="335"/>
<rect key="frame" x="20" y="269" width="388" height="388"/>
<constraints>
<constraint firstAttribute="width" secondItem="skm-4Q-SEq" secondAttribute="height" multiplier="1:1" id="F6J-6J-J5s"/>
</constraints>
</imageView>
</subviews>
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="thr-yb-z25" secondAttribute="trailing" id="0Yk-op-Sbr"/>
<constraint firstItem="skm-4Q-SEq" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="0tf-Kh-S2U"/>
<constraint firstItem="skm-4Q-SEq" firstAttribute="top" relation="greaterThanOrEqual" secondItem="Bcu-3y-fUS" secondAttribute="top" constant="20" id="45c-ps-A1j"/>
<constraint firstAttribute="trailing" secondItem="skm-4Q-SEq" secondAttribute="trailing" constant="20" id="Aji-Ek-k2q"/>
<constraint firstItem="Bcu-3y-fUS" firstAttribute="bottom" secondItem="thr-yb-z25" secondAttribute="bottom" id="FXS-f4-xfH"/>
<constraint firstAttribute="bottom" secondItem="thr-yb-z25" secondAttribute="bottom" id="FXS-f4-xfH"/>
<constraint firstItem="skm-4Q-SEq" firstAttribute="width" secondItem="skm-4Q-SEq" secondAttribute="height" multiplier="1:1" id="Q4h-h8-kju"/>
<constraint firstItem="Bcu-3y-fUS" firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="skm-4Q-SEq" secondAttribute="bottom" constant="20" id="TPw-KF-H85"/>
<constraint firstItem="thr-yb-z25" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="bHm-5w-uXH"/>
<constraint firstItem="thr-yb-z25" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="mnU-3N-lrW"/>
<constraint firstItem="skm-4Q-SEq" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="Ze5-6b-2t3" secondAttribute="leading" constant="20" id="uY3-7w-Cr7"/>
<constraint firstItem="skm-4Q-SEq" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="wkC-oo-tPK"/>
</constraints>
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
Expand Up @@ -97,7 +97,10 @@ struct AcronymRequest {
completion(.failure(.noData))
return
}
guard httpResponse.statusCode == 200, let jsonData = data else {
guard
httpResponse.statusCode == 200,
let jsonData = data
else {
if httpResponse.statusCode == 401 {
Auth().logout()
}
Expand Down
Expand Up @@ -49,7 +49,7 @@ class Auth {
}

func logout() {
self.token = nil
token = nil
DispatchQueue.main.async {
guard let applicationDelegate =
UIApplication.shared.delegate as? AppDelegate else {
Expand Down
Expand Up @@ -75,7 +75,10 @@ struct ResourceRequest<ResourceType> where ResourceType: Codable {
completion(.failure(.noData))
return
}
guard httpResponse.statusCode == 200, let jsonData = data else {
guard
httpResponse.statusCode == 200,
let jsonData = data
else {
if httpResponse.statusCode == 401 {
Auth().logout()
}
Expand Down
Expand Up @@ -30,7 +30,7 @@ import UIKit

class AcronymsTableViewController: UITableViewController {
// MARK: - Properties
var acronyms = [Acronym]()
var acronyms: [Acronym] = []
let acronymsRequest = ResourceRequest<Acronym>(resourcePath: "acronyms")

// MARK: - View Life Cycle
Expand Down
Expand Up @@ -53,11 +53,17 @@ class CreateAcronymTableViewController: UITableViewController {
}

@IBAction func save(_ sender: UIBarButtonItem) {
guard let shortText = acronymShortTextField.text, !shortText.isEmpty else {
guard
let shortText = acronymShortTextField.text,
!shortText.isEmpty
else {
ErrorPresenter.showError(message: "You must specify an acronym!", on: self)
return
}
guard let longText = acronymLongTextField.text, !longText.isEmpty else {
guard
let longText = acronymLongTextField.text,
!longText.isEmpty
else {
ErrorPresenter.showError(message: "You must specify a meaning!", on: self)
return
}
Expand Down
Expand Up @@ -47,10 +47,10 @@ class CreateCategoryTableViewController: UITableViewController {
guard
let name = nameTextField.text,
!name.isEmpty
else {
ErrorPresenter.showError(
message: "You must specify a name", on: self)
return
else {
ErrorPresenter.showError(
message: "You must specify a name", on: self)
return
}

let category = Category(name: name)
Expand Down
Expand Up @@ -46,17 +46,26 @@ class CreateUserTableViewController: UITableViewController {
}

@IBAction func save(_ sender: Any) {
guard let name = nameTextField.text, !name.isEmpty else {
guard
let name = nameTextField.text,
!name.isEmpty
else {
ErrorPresenter.showError(message: "You must specify a name", on: self)
return
}

guard let username = usernameTextField.text, !username.isEmpty else {
guard
let username = usernameTextField.text,
!username.isEmpty
else {
ErrorPresenter.showError(message: "You must specify a username", on: self)
return
}

guard let password = passwordTextField.text, !password.isEmpty else {
guard
let password = passwordTextField.text,
!password.isEmpty
else {
ErrorPresenter.showError(message: "You must specify a password", on: self)
return
}
Expand Down
Expand Up @@ -34,12 +34,18 @@ class LoginTableViewController: UITableViewController {
@IBOutlet weak var passwordTextField: UITextField!

@IBAction func loginTapped(_ sender: UIBarButtonItem) {
guard let username = usernameTextField.text, !username.isEmpty else {
guard
let username = usernameTextField.text,
!username.isEmpty
else {
ErrorPresenter.showError(message: "Please enter your username", on: self)
return
}

guard let password = passwordTextField.text, !password.isEmpty else {
guard
let password = passwordTextField.text,
!password.isEmpty
else {
ErrorPresenter.showError(message: "Please enter your password", on: self)
return
}
Expand Down
Expand Up @@ -29,7 +29,6 @@
import Vapor

struct UsersController: RouteCollection {

func boot(routes: RoutesBuilder) throws {
let usersRoute = routes.grouped("api", "users")
usersRoute.get(use: getAllHandler)
Expand Down
Expand Up @@ -29,7 +29,6 @@
import Vapor

struct WebsiteController: RouteCollection {

func boot(routes: RoutesBuilder) throws {
routes.get(use: indexHandler)
routes.get("acronyms", ":acronymID", use: acronymHandler)
Expand Down Expand Up @@ -114,7 +113,7 @@ struct WebsiteController: RouteCollection {
guard let id = acronym.id else {
return req.eventLoop.future(error: Abort(.internalServerError))
}
var categorySaves = [EventLoopFuture<Void>]()
var categorySaves: [EventLoopFuture<Void>] = []
for category in data.categories ?? [] {
categorySaves.append(Category.addCategory(category, to: acronym, on: req))
}
Expand Down Expand Up @@ -156,7 +155,7 @@ struct WebsiteController: RouteCollection {
let categoriesToAdd = newSet.subtracting(existingSet)
let categoriesToRemove = existingSet.subtracting(newSet)

var categoryResults = [EventLoopFuture<Void>]()
var categoryResults: [EventLoopFuture<Void>] = []
for newCategory in categoriesToAdd {
categoryResults.append(Category.addCategory(newCategory, to: acronym, on: req))
}
Expand Down
Expand Up @@ -57,7 +57,6 @@ final class AcronymTests: XCTestCase {
}

func testAcronymCanBeSavedWithAPI() throws {
let user = try User.create(on: app.db)
let createAcronymData = CreateAcronymData(short: acronymShort, long: acronymLong)

try app.test(.POST, acronymsURI, beforeRequest: { request in
Expand Down

0 comments on commit ab04445

Please sign in to comment.