Skip to content

Commit

Permalink
lazy loading and image caching demo
Browse files Browse the repository at this point in the history
This is just an introduction to the concept of lazy loading, the code however should not be used in production releases.
  • Loading branch information
codecat15 committed Jul 26, 2020
1 parent 3bc158d commit c6f8b98
Show file tree
Hide file tree
Showing 23 changed files with 1,249 additions and 0 deletions.
522 changes: 522 additions & 0 deletions lazyLoadingDemo/lazyLoadingDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "1C5518F8-3F0B-4A30-9724-E28503C1D2DC"
type = "1"
version = "2.0">
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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>SchemeUserState</key>
<dict>
<key>lazyLoadingDemo.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
37 changes: 37 additions & 0 deletions lazyLoadingDemo/lazyLoadingDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// AppDelegate.swift
// lazyLoadingDemo
//
// Created by CodeCat15 on 7/24/20.
// Copyright © 2020 CodeCat15. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions lazyLoadingDemo/lazyLoadingDemo/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Black on Transparent.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
40 changes: 40 additions & 0 deletions lazyLoadingDemo/lazyLoadingDemo/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<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="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="Z9A-eT-erv">
<rect key="frame" x="0.0" y="44" width="414" height="818"/>
</imageView>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="Z9A-eT-erv" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="4W2-BQ-mLL"/>
<constraint firstItem="Z9A-eT-erv" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="8t9-4H-wlf"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="Z9A-eT-erv" secondAttribute="bottom" id="PQR-yr-m33"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="Z9A-eT-erv" secondAttribute="trailing" id="ol7-AY-8Rw"/>
</constraints>
<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="-4" y="193"/>
</scene>
</scenes>
<resources>
<image name="LaunchImage" width="5000" height="3828"/>
</resources>
</document>
82 changes: 82 additions & 0 deletions lazyLoadingDemo/lazyLoadingDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--AnimalsVC-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="AnimalsVC" customModule="lazyLoadingDemo" 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>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="U0v-Mr-ggv">
<rect key="frame" x="0.0" y="44" width="414" height="818"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="animalsCell" rowHeight="140" id="wIX-8u-AJd" customClass="AnimalsTC" customModule="lazyLoadingDemo" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="414" height="140"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="wIX-8u-AJd" id="rxl-8H-qYQ">
<rect key="frame" x="0.0" y="0.0" width="414" height="140"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="AFm-Of-0bs" customClass="LazyImageView" customModule="lazyLoadingDemo" customModuleProvider="target">
<rect key="frame" x="20" y="20" width="100" height="100"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="amh-Tt-V27">
<rect key="frame" x="144" y="57" width="250" height="26"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="250" id="zCk-mq-Hju"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="22"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="AFm-Of-0bs" firstAttribute="leading" secondItem="rxl-8H-qYQ" secondAttribute="leadingMargin" id="1Xh-Al-aMQ"/>
<constraint firstItem="amh-Tt-V27" firstAttribute="leading" secondItem="AFm-Of-0bs" secondAttribute="trailing" constant="24" id="Hvf-cQ-JAi"/>
<constraint firstItem="AFm-Of-0bs" firstAttribute="top" secondItem="rxl-8H-qYQ" secondAttribute="topMargin" constant="9" id="MaB-F7-xsw"/>
<constraint firstItem="amh-Tt-V27" firstAttribute="trailing" secondItem="rxl-8H-qYQ" secondAttribute="trailingMargin" id="NKN-SX-yUd"/>
<constraint firstItem="amh-Tt-V27" firstAttribute="centerY" secondItem="AFm-Of-0bs" secondAttribute="centerY" id="Z3x-WM-mTa"/>
<constraint firstItem="amh-Tt-V27" firstAttribute="centerY" secondItem="rxl-8H-qYQ" secondAttribute="centerY" id="Zty-63-cbs"/>
<constraint firstItem="amh-Tt-V27" firstAttribute="top" secondItem="rxl-8H-qYQ" secondAttribute="topMargin" constant="46" id="iu6-Hg-e4J"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="imgAnimal" destination="AFm-Of-0bs" id="58h-aF-SkM"/>
<outlet property="lblName" destination="amh-Tt-V27" id="cFK-xe-3EZ"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="BYZ-38-t0r" id="ms7-Vg-psM"/>
<outlet property="delegate" destination="BYZ-38-t0r" id="dMj-nW-T1s"/>
</connections>
</tableView>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="U0v-Mr-ggv" secondAttribute="bottom" id="AtJ-Wg-rBb"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="U0v-Mr-ggv" secondAttribute="trailing" id="Dsp-k9-yTY"/>
<constraint firstItem="U0v-Mr-ggv" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="aQg-0c-iqZ"/>
<constraint firstItem="U0v-Mr-ggv" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="qF1-J6-udY"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
<outlet property="tblAnimalList" destination="U0v-Mr-ggv" id="LBU-aX-rBB"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-436.23188405797106" y="-234.375"/>
</scene>
</scenes>
</document>
27 changes: 27 additions & 0 deletions lazyLoadingDemo/lazyLoadingDemo/Controllers/AnimalsTC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// HerosTC.swift
// lazyLoadingDemo
//
// Created by CodeCat15 on 7/24/20.
// Copyright © 2020 CodeCat15. All rights reserved.
//

import UIKit

class AnimalsTC: UITableViewCell {

@IBOutlet weak var imgAnimal: LazyImageView!
@IBOutlet weak var lblName: UILabel!

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}

}
Loading

0 comments on commit c6f8b98

Please sign in to comment.