Tutorial app with sea mammals

Summary: Tutorial app for iOS. It follows the same theme as its android counterpart.

Reviewed By: passy

Differential Revision: D15184515

fbshipit-source-id: bb473c0fa863bb325bb33f8e42c8d6b3d9c640ff
This commit is contained in:
Pritesh Nandgaonkar
2019-05-03 05:15:15 -07:00
committed by Facebook Github Bot
parent 57af6fa2bf
commit c55bebd1be
10 changed files with 430 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
//
// AppDelegate.swift
// Tutorial
//
// Created by Pritesh Nandgaonkar on 5/2/19.
// Copyright © 2019 Facebook. All rights reserved.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
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.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}

View File

@@ -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"
}
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "sonarpattern.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

View File

@@ -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>

View File

@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<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="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Tutorial" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="sonarpattern" translatesAutoresizingMaskIntoConstraints="NO" id="ffr-94-Hk6">
<rect key="frame" x="0.0" y="44" width="414" height="852"/>
</imageView>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" allowsSelection="NO" rowHeight="400" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="cOy-QT-TlF">
<rect key="frame" x="0.0" y="44" width="414" height="818"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="separatorColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="sectionIndexBackgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="sectionIndexTrackingBackgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes>
<tableViewCell clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" restorationIdentifier="MarineMammalCell" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="MarineMammalCell" id="e5E-eZ-mj1" customClass="MarineMammalCell" customModule="Tutorial" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="414" height="400"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="e5E-eZ-mj1" id="iWq-Rh-IEO">
<rect key="frame" x="0.0" y="0.0" width="414" height="400"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="y26-ja-11Z">
<rect key="frame" x="8" y="8" width="398" height="384"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="8"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8FY-Jc-BXU">
<rect key="frame" x="16" y="347" width="59.5" height="37"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Uhh-dU-1b2">
<rect key="frame" x="24" y="355" width="43.5" height="21"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="y26-ja-11Z" secondAttribute="bottom" constant="8" id="5nX-fh-Rpv"/>
<constraint firstItem="8FY-Jc-BXU" firstAttribute="bottom" secondItem="Uhh-dU-1b2" secondAttribute="bottom" constant="8" id="6Qw-bX-64z"/>
<constraint firstItem="8FY-Jc-BXU" firstAttribute="top" secondItem="Uhh-dU-1b2" secondAttribute="top" constant="-8" id="CrW-c8-Uat"/>
<constraint firstAttribute="trailing" secondItem="y26-ja-11Z" secondAttribute="trailing" constant="8" id="H5f-33-eKv"/>
<constraint firstItem="8FY-Jc-BXU" firstAttribute="trailing" secondItem="Uhh-dU-1b2" secondAttribute="trailing" constant="8" id="Oft-VK-jBo"/>
<constraint firstItem="8FY-Jc-BXU" firstAttribute="leading" secondItem="Uhh-dU-1b2" secondAttribute="leading" constant="-8" id="PSn-D8-ChQ"/>
<constraint firstItem="Uhh-dU-1b2" firstAttribute="leading" secondItem="iWq-Rh-IEO" secondAttribute="leading" constant="24" id="Pdj-di-d4t"/>
<constraint firstAttribute="bottom" secondItem="Uhh-dU-1b2" secondAttribute="bottom" constant="24" id="Rdf-Qx-U3Z"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="Uhh-dU-1b2" secondAttribute="trailing" constant="16" id="WQ9-eF-sCh"/>
<constraint firstItem="y26-ja-11Z" firstAttribute="leading" secondItem="iWq-Rh-IEO" secondAttribute="leading" constant="8" id="ai5-tl-QpZ"/>
<constraint firstItem="y26-ja-11Z" firstAttribute="top" secondItem="iWq-Rh-IEO" secondAttribute="top" constant="8" id="mJ5-TV-QaV"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<outlet property="name" destination="Uhh-dU-1b2" id="MLM-Fa-aGr"/>
<outlet property="photo" destination="y26-ja-11Z" id="h5f-AJ-VU2"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="BYZ-38-t0r" id="VKS-h2-Bg4"/>
</connections>
</tableView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="ffr-94-Hk6" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="48n-jE-fBp"/>
<constraint firstItem="cOy-QT-TlF" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="8lE-wr-nv5"/>
<constraint firstItem="cOy-QT-TlF" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="MqQ-X2-zkf"/>
<constraint firstItem="cOy-QT-TlF" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="My1-Zc-Q1k"/>
<constraint firstItem="cOy-QT-TlF" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="kFG-PK-tLy"/>
<constraint firstAttribute="bottom" secondItem="ffr-94-Hk6" secondAttribute="bottom" id="l6N-49-PQi"/>
<constraint firstItem="ffr-94-Hk6" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="t5d-B2-9Zn"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="ffr-94-Hk6" secondAttribute="trailing" id="xlH-mZ-CIh"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="137.68115942028987" y="138.61607142857142"/>
</scene>
</scenes>
<resources>
<image name="sonarpattern" width="421.5" height="658.5"/>
</resources>
</document>

View File

@@ -0,0 +1,47 @@
//
// MarineMammalCell.swift
// Tutorial
//
// Created by Pritesh Nandgaonkar on 5/2/19.
// Copyright © 2019 Facebook. All rights reserved.
//
import Foundation
import UIKit
struct MarineMammal {
let name: String
let image: URL
}
class MarineMammalCell: UITableViewCell {
@IBOutlet weak var photo: UIImageView!
@IBOutlet weak var name: UILabel!
func populate(marineMammal: MarineMammal) {
let task = URLSession.shared.dataTask(with: marineMammal.image) { [weak self] (data, response, error) in
if let unwrappedError = error {
print(unwrappedError)
return
}
guard let unwrappedData = data else {
print("No Image data received")
return
}
let image = UIImage(data: unwrappedData)
guard let unwrappedImage = image else {
print("Failed to instantiate an image from Image data")
return
}
DispatchQueue.main.async {
self?.photo.image = unwrappedImage
}
}
task.resume()
self.name.text = marineMammal.name
}
}

View File

@@ -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>

View File

@@ -0,0 +1,37 @@
//
// ViewController.swift
// Tutorial
//
// Created by Pritesh Nandgaonkar on 5/2/19.
// Copyright © 2019 Facebook. All rights reserved.
//
import UIKit
class ViewController: UIViewController, UITableViewDataSource {
let marineMammals: [MarineMammal] = [
MarineMammal(name: "Polar Bear", image: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Ursus_maritimus_4_1996-08-04.jpg/190px-Ursus_maritimus_4_1996-08-04.jpg")!),
MarineMammal(name: "Sea Otter", image: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Sea_otter_cropped.jpg/220px-Sea_otter_cropped.jpg")!),
MarineMammal(name: "West Indian Manatee", image: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/FL_fig04.jpg/230px-FL_fig04.jpg")!),
MarineMammal(name: "Bottlenose Dolphin", image: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/10/Tursiops_truncatus_01.jpg/220px-Tursiops_truncatus_01.jpg")!),
]
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return marineMammals.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MarineMammalCell", for: indexPath)
guard let mammalCell = cell as? MarineMammalCell else {
fatalError("Wrong cell identifier")
}
mammalCell.populate(marineMammal: marineMammals[indexPath.row])
return mammalCell
}
}