Skip to content
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
381 changes: 381 additions & 0 deletions Detail.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Detail/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}
}
98 changes: 98 additions & 0 deletions Detail/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"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"
}
}
6 changes: 6 additions & 0 deletions Detail/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
25 changes: 25 additions & 0 deletions Detail/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" 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>
236 changes: 236 additions & 0 deletions Detail/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions Detail/DetailViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import UIKit

class DetailViewController: UIViewController {
var person: Person?

@IBOutlet weak var nameField: UITextField!
@IBOutlet weak var cohortField: UITextField!

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

guard let person = person else { return }
nameField.text = person.name
cohortField.text = person.cohort
}

@IBAction func save(_ sender: Any) {
guard let person = person else { return }
guard let name = nameField.text, !name.isEmpty else { return }
person.name = name
person.cohort = cohortField.text ?? ""
navigationController?.popViewController(animated: true)
Firebase.save(item: person) { (success) in
guard success else {return}
}
}
}
20 changes: 20 additions & 0 deletions Detail/EntryCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import UIKit

class EntryCell: UITableViewCell {
static let reuseIdentifier = "entry cell"

@IBOutlet weak var nameField: UITextField!

@IBOutlet weak var cohortField: UITextField!

@IBAction func add(_ sender: Any) {
guard let name = nameField.text, !name.isEmpty else { return }
let cohort = cohortField.text ?? ""
let person = Person(name: name, cohort: cohort)
Model.shared.add(person: person) {
return
}
nameField.text = nil
cohortField.text = nil
}
}
88 changes: 88 additions & 0 deletions Detail/EntryCell.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" rowHeight="212" id="B1E-df-MsY" customClass="EntryCell" customModule="Detail" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="374" height="128"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="B1E-df-MsY" id="v8p-9u-qIK">
<rect key="frame" x="0.0" y="0.0" width="374" height="127.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalCentering" translatesAutoresizingMaskIntoConstraints="NO" id="MfI-71-sdm">
<rect key="frame" x="24" y="19" width="326" height="90"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" alignment="lastBaseline" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="2b5-iY-Nxt">
<rect key="frame" x="0.0" y="0.0" width="326" height="24"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Name:" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pID-SS-HJH">
<rect key="frame" x="0.0" y="3.5" width="58" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Name" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="fTM-eE-VC1">
<rect key="frame" x="66" y="0.0" width="260" height="30"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" alignment="lastBaseline" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="Han-aq-b7n">
<rect key="frame" x="0.0" y="31.5" width="326" height="24"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Cohort:" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1Xx-D6-6uk">
<rect key="frame" x="0.0" y="3.5" width="58" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Cohort" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="9By-PR-9uj">
<rect key="frame" x="66" y="0.0" width="260" height="30"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
<viewLayoutGuide key="safeArea" id="PiP-d1-TVB"/>
</stackView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="c7m-RO-NfC">
<rect key="frame" x="0.0" y="60" width="326" height="30"/>
<state key="normal" title="Add"/>
<connections>
<action selector="add:" destination="B1E-df-MsY" eventType="touchUpInside" id="ZeD-3g-6LS"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="1Xx-D6-6uk" firstAttribute="width" secondItem="pID-SS-HJH" secondAttribute="width" id="V1s-Bq-lh9"/>
</constraints>
</stackView>
</subviews>
<color key="backgroundColor" red="0.9490865786668613" green="0.9490865786668613" blue="0.9490865786668613" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="MfI-71-sdm" firstAttribute="top" secondItem="v8p-9u-qIK" secondAttribute="topMargin" constant="8" id="2nz-hR-tHZ"/>
<constraint firstAttribute="trailingMargin" secondItem="MfI-71-sdm" secondAttribute="trailing" constant="8" id="7hK-DA-ofZ"/>
<constraint firstItem="MfI-71-sdm" firstAttribute="leading" secondItem="v8p-9u-qIK" secondAttribute="leadingMargin" constant="8" id="Cu5-vd-QQg"/>
<constraint firstAttribute="bottomMargin" secondItem="MfI-71-sdm" secondAttribute="bottom" constant="8" id="LbT-f1-wi1"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="cohortField" destination="9By-PR-9uj" id="ons-E5-hmz"/>
<outlet property="nameField" destination="fTM-eE-VC1" id="HS3-zj-AMa"/>
</connections>
<point key="canvasLocation" x="272" y="-191.6041979010495"/>
</tableViewCell>
</objects>
</document>
2 changes: 1 addition & 1 deletion Firebase.swift → Detail/Firebase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation


class Firebase<Item: Codable & FirebaseItem> {
static var baseURL: URL! { return URL(string: "https://put-and-post.firebaseio.com/") }
static var baseURL: URL! { return URL(string: "https://ios-firebase-project-53e55.firebaseio.com/") }

static func requestURL(_ method: String, for recordIdentifier: String = "unknownid") -> URL {
switch method {
Expand Down
File renamed without changes.
45 changes: 45 additions & 0 deletions Detail/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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>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>
61 changes: 61 additions & 0 deletions Detail/Model.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import Foundation

class Model {
static let shared = Model()
private init() {}
var delegate: ModelUpdateClient?

var persons: [Person] = []

func count() -> Int {
return persons.count
}

func person(forIndex index: Int) -> Person {
return persons[index]
}
// func person(forIndex index: Int) -> Person {
// return persons[index]
// }

func add(person: Person, completion: @escaping () -> Void) {
persons.append(person)
delegate?.modelDidUpdate()

Firebase<Person>.save(item: person) { success in
guard success else {return}
DispatchQueue.main.async { completion() }
}
}

func deletePerson(at indexPath: IndexPath, completion: @escaping () -> Void) {
let person = persons[indexPath.row]
persons.remove(at: indexPath.row)


Firebase<Person>.delete(item: person) { success in
guard success else {return}
DispatchQueue.main.async {
completion()

}

}
}
// Call this to replace the device with one with a new UUID
func updatePerson(at indexPath: IndexPath, completion: @escaping () -> Void) {
let person = persons[indexPath.row]

// local
let detailPerson = DetailViewController()
person.name = detailPerson.nameField.text ?? ""
person.cohort = detailPerson.cohortField.text ?? ""

// remote
Firebase<Person>.save(item: person) { success in
guard success else { return }
DispatchQueue.main.async { completion() }
}
}

}
Loading