Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wolframAlphaapi_withloadingIndicator #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions APIClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
874D06601CEF295E009A494D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 874D065F1CEF295E009A494D /* Assets.xcassets */; };
874D06631CEF295E009A494D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 874D06611CEF295E009A494D /* LaunchScreen.storyboard */; };
A526FDEE5BF2D1BC3C97B9FA /* Pods_APIClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BD8A5B3E1266D5298CABE44A /* Pods_APIClient.framework */; };
C2A151551E9E172700B906B7 /* WolframalphaViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2A151541E9E172700B906B7 /* WolframalphaViewController.swift */; };
C2B44A0A1E9E2A9000CD4B11 /* Wolfram.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2B44A091E9E2A9000CD4B11 /* Wolfram.swift */; };
E9294E7F05F2671186BD1359 /* Pods_APIClientTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4FFA0A7AA37697BD5CBC3211 /* Pods_APIClientTests.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -47,9 +49,10 @@
87EC714F1CFA380F00FBDDDE /* APIClientTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = APIClientTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
87EC71531CFA380F00FBDDDE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
87EC715D1CFA381600FBDDDE /* APIClientUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = APIClientUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
87EC71611CFA381600FBDDDE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
93EFAB13AE62F1B6FB2683B2 /* Pods-APIClient.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClient.debug.xcconfig"; path = "Pods/Target Support Files/Pods-APIClient/Pods-APIClient.debug.xcconfig"; sourceTree = "<group>"; };
BD8A5B3E1266D5298CABE44A /* Pods_APIClient.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_APIClient.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C2A151541E9E172700B906B7 /* WolframalphaViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WolframalphaViewController.swift; sourceTree = "<group>"; };
C2B44A091E9E2A9000CD4B11 /* Wolfram.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Wolfram.swift; path = ../Wolfram.swift; sourceTree = "<group>"; };
C67B3B3E7990BE278400974F /* Pods-APIClientUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClientUITests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-APIClientUITests/Pods-APIClientUITests.debug.xcconfig"; sourceTree = "<group>"; };
F8B9811B1068B05E73195990 /* Pods-APIClientTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClientTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-APIClientTests/Pods-APIClientTests.debug.xcconfig"; sourceTree = "<group>"; };
FFE13D543A95D28F27CFBDA4 /* Pods-APIClient.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClient.release.xcconfig"; path = "Pods/Target Support Files/Pods-APIClient/Pods-APIClient.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -119,7 +122,6 @@
children = (
874D06571CEF295E009A494D /* APIClient */,
87EC71501CFA380F00FBDDDE /* APIClientTests */,
87EC715E1CFA381600FBDDDE /* APIClientUITests */,
874D06561CEF295E009A494D /* Products */,
CF558E3374C5C3F956C82B81 /* Pods */,
D9BE20B845CB84F96D784197 /* Frameworks */,
Expand All @@ -141,6 +143,8 @@
children = (
874D06581CEF295E009A494D /* AppDelegate.swift */,
874D065C1CEF295E009A494D /* Main.storyboard */,
C2A151541E9E172700B906B7 /* WolframalphaViewController.swift */,
C2B44A091E9E2A9000CD4B11 /* Wolfram.swift */,
872A27571CF0D4E200A988C4 /* View Controller */,
872A27581CF0D4EB00A988C4 /* View */,
872A27591CF0D64A00A988C4 /* Model */,
Expand All @@ -157,14 +161,6 @@
path = APIClientTests;
sourceTree = "<group>";
};
87EC715E1CFA381600FBDDDE /* APIClientUITests */ = {
isa = PBXGroup;
children = (
87EC71611CFA381600FBDDDE /* Info.plist */,
);
path = APIClientUITests;
sourceTree = "<group>";
};
CF558E3374C5C3F956C82B81 /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -468,6 +464,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C2B44A0A1E9E2A9000CD4B11 /* Wolfram.swift in Sources */,
C2A151551E9E172700B906B7 /* WolframalphaViewController.swift in Sources */,
874D06591CEF295E009A494D /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
59 changes: 50 additions & 9 deletions APIClient/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="E10-YL-lxp">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="E10-YL-lxp">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
Expand All @@ -21,24 +26,60 @@
</objects>
<point key="canvasLocation" x="-658" y="301"/>
</scene>
<!--View Controller-->
<!--Wolframalpha View Controller-->
<scene sceneID="adh-8k-Iuh">
<objects>
<viewController id="rPr-Fp-ALE" sceneMemberID="viewController">
<viewController id="rPr-Fp-ALE" customClass="WolframalphaViewController" customModule="APIClient" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="pj8-zF-1z6"/>
<viewControllerLayoutGuide type="bottom" id="kt2-9S-3TK"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="rEB-Za-Zhx">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<subviews>
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="H4E-tx-Nvd">
<rect key="frame" x="177" y="72" width="20" height="20"/>
</activityIndicatorView>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="Hgb-z1-9mA">
<rect key="frame" x="16" y="92" width="343" height="575"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="H4E-tx-Nvd" firstAttribute="top" secondItem="pj8-zF-1z6" secondAttribute="bottom" constant="8" id="1wE-X3-Nto"/>
<constraint firstItem="kt2-9S-3TK" firstAttribute="top" secondItem="Hgb-z1-9mA" secondAttribute="bottom" id="2Vl-Er-bsm"/>
<constraint firstItem="H4E-tx-Nvd" firstAttribute="centerX" secondItem="rEB-Za-Zhx" secondAttribute="centerX" id="oZy-HW-r4h"/>
<constraint firstItem="Hgb-z1-9mA" firstAttribute="top" secondItem="H4E-tx-Nvd" secondAttribute="bottom" id="sOv-eQ-yBp"/>
<constraint firstAttribute="trailingMargin" secondItem="Hgb-z1-9mA" secondAttribute="trailing" id="t72-hH-GY4"/>
<constraint firstItem="Hgb-z1-9mA" firstAttribute="leading" secondItem="rEB-Za-Zhx" secondAttribute="leadingMargin" id="v7D-oT-AZf"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="CZR-l9-xMg"/>
<navigationItem key="navigationItem" id="CZR-l9-xMg">
<nil key="title"/>
<textField key="titleView" opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" id="gif-nb-Vad">
<rect key="frame" x="112.5" y="7" width="150" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="rPr-Fp-ALE" id="4gZ-Oz-5pM"/>
</connections>
</textField>
</navigationItem>
<connections>
<outlet property="answerLabel" destination="Hgb-z1-9mA" id="wvf-gA-KJk"/>
<outlet property="inputTextfield" destination="gif-nb-Vad" id="wLo-fd-pA6"/>
<outlet property="loadingIndicator" destination="H4E-tx-Nvd" id="CxR-Jn-oNN"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="OaC-W5-AeM" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="65" y="301"/>
<point key="canvasLocation" x="300" y="256.82158920539734"/>
</scene>
</scenes>
</document>
11 changes: 11 additions & 0 deletions APIClient/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,16 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>api.wolframalpha.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
</dict>
</plist>
59 changes: 59 additions & 0 deletions APIClient/WolframalphaViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// WolframalphaViewController.swift
// APIClient
//
// Created by Katja D on 12.04.17.
// Copyright © 2017 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import UIKit
import Moya

class WolframalphaViewController: UIViewController,
UITextFieldDelegate{


@IBOutlet var inputTextfield: UITextField!

@IBOutlet weak var loadingIndicator: UIActivityIndicatorView!


@IBOutlet weak var answerLabel: UITextView!

func textFieldShouldReturn(_ textField: UITextField) -> Bool {

guard let input = textField.text else {
return true
}
loadingIndicator.startAnimating()

let provider = MoyaProvider<Wolframalphaapi>()

let query = Wolframalphaapi.shortAnswer(query: input)

provider.request(query) { result in

self.loadingIndicator.stopAnimating()

switch result {
case .success(let response):
let answer = String(data: response.data,
encoding: .utf8)
self.answerLabel.text = answer


case .failure(let error):

print(error)

}

}

return true
}



}
Loading