Commit 2d867850 authored by Mladen Jakovljevic's avatar Mladen Jakovljevic

Initial commit.

parents
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
## Playgrounds
timeline.xctimeline
playground.xcworkspace
# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
.build/
# IDEA
.idea/
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:State.xcodeproj">
</FileRef>
</Workspace>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
//
// AppDelegate.swift
// State
//
// Created by Mladen Jakovljevic on 02.05.2018..
// Copyright © 2018 codecentric. All rights reserved.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if AppDelegate.isUITestingEnabled {
setBoolDefaults(environmentKey: "keepScreenOnEnvKey", defaultsKey: ViewController.keepScreenOnKey)
setBoolDefaults(environmentKey: "autoRefreshEnvKey", defaultsKey: ViewController.autoRefreshKey)
}
return true
}
static var isUITestingEnabled: Bool {
get {
return ProcessInfo.processInfo.arguments.contains("UI-Testing")
}
}
private func setBoolDefaults(environmentKey: String, defaultsKey: String) {
let environment = ProcessInfo.processInfo.environment
if let boolArgument = environment[environmentKey] {
if boolArgument == "YES" {
UserDefaults.standard.set(true, forKey: defaultsKey)
} else if boolArgument == "NO" {
UserDefaults.standard.set(false, forKey: defaultsKey)
}
}
}
private func setStringDefaults(environmentKey: String, defaultsKey: String) {
let environment = ProcessInfo.processInfo.environment
if let stringArgument = environment[environmentKey] {
UserDefaults.standard.set(stringArgument, forKey: defaultsKey)
}
}
}
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" systemVersion="17A277" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<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"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="fDG-20-nr1">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="xzu-qQ-4u2">
<objects>
<viewController id="fDG-20-nr1" customClass="ViewController" customModule="State" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="WEZ-nt-xK5">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Keep screen on" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EAR-QD-zRU">
<rect key="frame" x="16" y="91" width="126" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<accessibility key="accessibilityConfiguration" identifier="lengthyTextLabel"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Screen stays turned on" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Cuf-Sw-797">
<rect key="frame" x="16" y="120" width="284" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="oFy-VV-owk">
<rect key="frame" x="308" y="103" width="49" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<accessibility key="accessibilityConfiguration" identifier="keepScreenOnSwitch"/>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Auto refresh on start" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="c6G-QB-aRk">
<rect key="frame" x="16" y="179" width="171" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Refreshing on start activated" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="NPd-Xb-5R2">
<rect key="frame" x="16" y="208" width="264" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="LZw-G4-cmD">
<rect key="frame" x="308" y="187" width="49" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<accessibility key="accessibilityConfiguration" identifier="autoRefreshSwitch"/>
</switch>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cqn-Xx-SKa">
<rect key="frame" x="207" y="606" width="152" height="41"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES" heightSizable="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<state key="normal" title="Continue"/>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="wvV-yL-dGj"/>
</view>
<connections>
<outlet property="captionAutoRefresh" destination="NPd-Xb-5R2" id="qN5-ay-NDV"/>
<outlet property="captionKeepScreenOn" destination="Cuf-Sw-797" id="Ct6-Yd-olc"/>
<outlet property="continueButton" destination="cqn-Xx-SKa" id="wGp-z8-7i2"/>
<outlet property="switchAutoRefresh" destination="LZw-G4-cmD" id="4KX-4U-9zx"/>
<outlet property="switchKeepScreenOn" destination="oFy-VV-owk" id="8Yr-Wy-JzW"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="QOK-nk-ICO" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="133.59999999999999" y="340.47976011994007"/>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>State</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
//
// ViewController.swift
// State
//
// Created by Mladen Jakovljevic on 02.05.2018..
// Copyright © 2018 codecentric. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var switchKeepScreenOn: UISwitch!
@IBOutlet weak var switchAutoRefresh: UISwitch!
@IBOutlet weak var captionKeepScreenOn: UILabel!
@IBOutlet weak var captionAutoRefresh: UILabel!
@IBOutlet weak var continueButton: UIButton!
let defaults = UserDefaults.standard
static let keepScreenOnKey = "keepScreenOn"
static let autoRefreshKey = "autoRefresh"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
switchKeepScreenOn.isOn = defaults.bool(forKey: ViewController.keepScreenOnKey)
switchAutoRefresh.isOn = defaults.bool(forKey: ViewController.autoRefreshKey)
switchKeepScreenOn.addTarget(self, action: #selector(keepScreenOnChanged), for: UIControlEvents.valueChanged)
switchAutoRefresh.addTarget(self, action: #selector(autoRefreshChanged), for: UIControlEvents.valueChanged)
setState()
captionKeepScreenOn.accessibilityIdentifier = "lengthyTextLabel"
}
@objc func keepScreenOnChanged(sw: UISwitch) {
setState()
defaults.set(sw.isOn, forKey: ViewController.keepScreenOnKey)
}
@objc func autoRefreshChanged(sw: UISwitch) {
setState()
defaults.set(sw.isOn, forKey: ViewController.autoRefreshKey)
}
private func setState() {
if switchKeepScreenOn.isOn {
captionKeepScreenOn.text = "Screen stays turned on"
} else {
captionKeepScreenOn.text = "Tap switch to keep screen on"
continueButton.isEnabled = false
}
if switchAutoRefresh.isOn {
captionAutoRefresh.text = "Refreshing on start activated"
} else {
captionAutoRefresh.text = "Enable refreshing on start"
continueButton.isEnabled = false
}
if switchKeepScreenOn.isOn && switchAutoRefresh.isOn {
continueButton.isEnabled = true
} else {
continueButton.isEnabled = false
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
//
// StateTests.swift
// StateTests
//
// Created by Mladen Jakovljevic on 02.05.2018..
// Copyright © 2018 codecentric. All rights reserved.
//
import XCTest
@testable import State
class StateTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
//
// StateUITests.swift
// StateUITests
//
// Created by Mladen Jakovljevic on 02.05.2018..
// Copyright © 2018 codecentric. All rights reserved.
//
import XCTest
class StateUITests: XCTestCase {
let app = XCUIApplication()
static let keepScreenOnEnvKey = "keepScreenOnEnvKey"
static let autoRefreshEnvKey = "autoRefreshEnvKey"
override func setUp() {
super.setUp()
continueAfterFailure = false
app.launchArguments += ["UI-Testing"]
}
func testTurningOnKeepScreenOnSwitch() {
app.launchEnvironment[StateUITests.keepScreenOnEnvKey] = "NO"
app.launch()
app.switches["keepScreenOnSwitch"].tap()
XCTAssertTrue(app.staticTexts["Screen stays turned on"].exists,
"Error: Turnixng switch on doesn't change caption text.")
sleep(1)
}
func testCaptionTextForTurnedOnKeepScreenOnSwitch() {
app.launchEnvironment[StateUITests.keepScreenOnEnvKey] = "YES"
app.launch()
XCTAssertTrue(app.staticTexts["Screen stays turned on"].exists,
"Caption text for Keep Screen On switch is not correct on app startup.")
sleep(1)
}
func testTurningOnAutoRefreshSwitch() {
app.launchEnvironment[StateUITests.autoRefreshEnvKey] = "NO"
app.launch()
app.switches["autoRefreshSwitch"].tap()
XCTAssertTrue(app.staticTexts["Refreshing on start activated"].exists,
"Error: Turning switch on doesn't change caption text.")
sleep(1)
}
func testCaptionTextForTurnedOnAutoRefreshSwitch() {
app.launchEnvironment[StateUITests.autoRefreshEnvKey] = "YES"
app.launch()
XCTAssertTrue(app.staticTexts["Refreshing on start activated"].exists,
"Caption text for Auto Refresh switch is not correct on app startup.")
sleep(1)
}
func testContinueButtonEnabled() {
app.launchEnvironment[StateUITests.keepScreenOnEnvKey] = "NO"
app.launchEnvironment[StateUITests.autoRefreshEnvKey] = "NO"
app.launch()
app.switches["autoRefreshSwitch"].tap()
app.switches["keepScreenOnSwitch"].tap()
XCTAssertTrue(app.buttons["Continue"].isEnabled,
"Error: Continue button is not enabled when both switches are turned on.")
sleep(1)
}
}
Markdown is supported
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