Archived
1
Fork 0

Remove UICollectionView subclass to prevent a serious bug

This commit is contained in:
redstrate 2020-05-24 22:55:30 -04:00
parent 46276860ce
commit 91e2b63804
6 changed files with 109 additions and 85 deletions

View file

@ -20,7 +20,7 @@
0361A5122346A38100639E67 /* PostViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0361A5112346A38100639E67 /* PostViewController.swift */; }; 0361A5122346A38100639E67 /* PostViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0361A5112346A38100639E67 /* PostViewController.swift */; };
0361A514234828D000639E67 /* EditTagsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0361A513234828D000639E67 /* EditTagsViewController.swift */; }; 0361A514234828D000639E67 /* EditTagsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0361A513234828D000639E67 /* EditTagsViewController.swift */; };
0361A51623482A7D00639E67 /* TagViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0361A51523482A7D00639E67 /* TagViewCell.swift */; }; 0361A51623482A7D00639E67 /* TagViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0361A51523482A7D00639E67 /* TagViewCell.swift */; };
03F92BA22349635C0000DC1C /* PostCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F92BA12349635C0000DC1C /* PostCollectionView.swift */; }; 03F92BA22349635C0000DC1C /* PostsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F92BA12349635C0000DC1C /* PostsManager.swift */; };
03F92BA4234967E00000DC1C /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F92BA3234967E00000DC1C /* SearchViewController.swift */; }; 03F92BA4234967E00000DC1C /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F92BA3234967E00000DC1C /* SearchViewController.swift */; };
03F92BA6234969800000DC1C /* TagViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F92BA5234969800000DC1C /* TagViewController.swift */; }; 03F92BA6234969800000DC1C /* TagViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F92BA5234969800000DC1C /* TagViewController.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -42,7 +42,7 @@
0361A5112346A38100639E67 /* PostViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewController.swift; sourceTree = "<group>"; }; 0361A5112346A38100639E67 /* PostViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewController.swift; sourceTree = "<group>"; };
0361A513234828D000639E67 /* EditTagsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditTagsViewController.swift; sourceTree = "<group>"; }; 0361A513234828D000639E67 /* EditTagsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditTagsViewController.swift; sourceTree = "<group>"; };
0361A51523482A7D00639E67 /* TagViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagViewCell.swift; sourceTree = "<group>"; }; 0361A51523482A7D00639E67 /* TagViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagViewCell.swift; sourceTree = "<group>"; };
03F92BA12349635C0000DC1C /* PostCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostCollectionView.swift; sourceTree = "<group>"; }; 03F92BA12349635C0000DC1C /* PostsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostsManager.swift; sourceTree = "<group>"; };
03F92BA3234967E00000DC1C /* SearchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchViewController.swift; sourceTree = "<group>"; }; 03F92BA3234967E00000DC1C /* SearchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchViewController.swift; sourceTree = "<group>"; };
03F92BA5234969800000DC1C /* TagViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagViewController.swift; sourceTree = "<group>"; }; 03F92BA5234969800000DC1C /* TagViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@ -90,7 +90,7 @@
0361A5112346A38100639E67 /* PostViewController.swift */, 0361A5112346A38100639E67 /* PostViewController.swift */,
0361A513234828D000639E67 /* EditTagsViewController.swift */, 0361A513234828D000639E67 /* EditTagsViewController.swift */,
0361A51523482A7D00639E67 /* TagViewCell.swift */, 0361A51523482A7D00639E67 /* TagViewCell.swift */,
03F92BA12349635C0000DC1C /* PostCollectionView.swift */, 03F92BA12349635C0000DC1C /* PostsManager.swift */,
03F92BA3234967E00000DC1C /* SearchViewController.swift */, 03F92BA3234967E00000DC1C /* SearchViewController.swift */,
03F92BA5234969800000DC1C /* TagViewController.swift */, 03F92BA5234969800000DC1C /* TagViewController.swift */,
03093522235660E100E44910 /* ReverseImageViewController.swift */, 03093522235660E100E44910 /* ReverseImageViewController.swift */,
@ -171,7 +171,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
03F92BA4234967E00000DC1C /* SearchViewController.swift in Sources */, 03F92BA4234967E00000DC1C /* SearchViewController.swift in Sources */,
03F92BA22349635C0000DC1C /* PostCollectionView.swift in Sources */, 03F92BA22349635C0000DC1C /* PostsManager.swift in Sources */,
0361A5122346A38100639E67 /* PostViewController.swift in Sources */, 0361A5122346A38100639E67 /* PostViewController.swift in Sources */,
0361A502234690C000639E67 /* Gallery.xcdatamodeld in Sources */, 0361A502234690C000639E67 /* Gallery.xcdatamodeld in Sources */,
0361A4FC234690C000639E67 /* ViewController.swift in Sources */, 0361A4FC234690C000639E67 /* ViewController.swift in Sources */,

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Q6f-oJ-eRP"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Q6f-oJ-eRP">
<device id="retina6_1" orientation="portrait" appearance="light"/> <device id="mac" appearance="light"/>
<dependencies> <dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/> <capability name="Safe area layout guides" minToolsVersion="9.0"/>
@ -13,7 +13,7 @@
<objects> <objects>
<navigationController id="Q6f-oJ-eRP" sceneMemberID="viewController"> <navigationController id="Q6f-oJ-eRP" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="bva-S3-Kph"> <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="bva-S3-Kph">
<rect key="frame" x="0.0" y="44" width="414" height="44"/> <rect key="frame" x="0.0" y="0.0" width="800" height="50"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
</navigationBar> </navigationBar>
<connections> <connections>
@ -29,11 +29,11 @@
<objects> <objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController"> <viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC"> <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <rect key="frame" x="0.0" y="0.0" width="800" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="nHo-hC-uT9" customClass="PostCollectionView" customModule="Gallery" customModuleProvider="target"> <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="nHo-hC-uT9">
<rect key="frame" x="0.0" y="88" width="414" height="770"/> <rect key="frame" x="0.0" y="50" width="800" height="550"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="N2K-Me-YT7"> <collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="N2K-Me-YT7">
<size key="itemSize" width="50" height="50"/> <size key="itemSize" width="50" height="50"/>
@ -85,7 +85,7 @@
</barButtonItem> </barButtonItem>
</navigationItem> </navigationItem>
<connections> <connections>
<outlet property="collectionView" destination="nHo-hC-uT9" id="mmZ-7N-1va"/> <outlet property="collectionView" destination="nHo-hC-uT9" id="xzY-kS-DmY"/>
</connections> </connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
@ -97,11 +97,11 @@
<objects> <objects>
<viewController storyboardIdentifier="PostViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="jQf-RA-c2I" customClass="PostViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController"> <viewController storyboardIdentifier="PostViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="jQf-RA-c2I" customClass="PostViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8Jm-eh-tzq"> <view key="view" contentMode="scaleToFill" id="8Jm-eh-tzq">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <rect key="frame" x="0.0" y="0.0" width="800" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<imageView clipsSubviews="YES" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="7Hd-Ax-kkQ"> <imageView clipsSubviews="YES" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="7Hd-Ax-kkQ">
<rect key="frame" x="0.0" y="88" width="414" height="774"/> <rect key="frame" x="0.0" y="50" width="800" height="550"/>
<gestureRecognizers/> <gestureRecognizers/>
<connections> <connections>
<outletCollection property="gestureRecognizers" destination="uQa-Iu-LrE" appends="YES" id="Qec-Ks-5Aj"/> <outletCollection property="gestureRecognizers" destination="uQa-Iu-LrE" appends="YES" id="Qec-Ks-5Aj"/>
@ -125,14 +125,14 @@
<action selector="shareAction:" destination="jQf-RA-c2I" id="H7r-Iw-ZQ6"/> <action selector="shareAction:" destination="jQf-RA-c2I" id="H7r-Iw-ZQ6"/>
</connections> </connections>
</barButtonItem> </barButtonItem>
<barButtonItem title="Tags" image="pencil" catalog="system" id="8d3-sz-ihb"> <barButtonItem title="Tags" image="tag" catalog="system" id="8d3-sz-ihb">
<connections> <connections>
<segue destination="3TL-qD-pbO" kind="popoverPresentation" identifier="showTags" popoverAnchorBarButtonItem="8d3-sz-ihb" id="QRP-ua-ucM"> <segue destination="3TL-qD-pbO" kind="popoverPresentation" identifier="showTags" popoverAnchorBarButtonItem="8d3-sz-ihb" id="QRP-ua-ucM">
<popoverArrowDirection key="popoverArrowDirection" up="YES" down="YES" left="YES" right="YES"/> <popoverArrowDirection key="popoverArrowDirection" up="YES" down="YES" left="YES" right="YES"/>
</segue> </segue>
</connections> </connections>
</barButtonItem> </barButtonItem>
<barButtonItem title="Info" id="4FI-KY-8yL"> <barButtonItem title="Info" image="info.circle" catalog="system" id="4FI-KY-8yL">
<connections> <connections>
<segue destination="MaR-nc-wxI" kind="popoverPresentation" identifier="showInfo" popoverAnchorBarButtonItem="4FI-KY-8yL" id="OSs-lm-jsP"> <segue destination="MaR-nc-wxI" kind="popoverPresentation" identifier="showInfo" popoverAnchorBarButtonItem="4FI-KY-8yL" id="OSs-lm-jsP">
<popoverArrowDirection key="popoverArrowDirection" up="YES" down="YES" left="YES" right="YES"/> <popoverArrowDirection key="popoverArrowDirection" up="YES" down="YES" left="YES" right="YES"/>
@ -160,22 +160,22 @@
<objects> <objects>
<viewController storyboardIdentifier="EditTagsViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="3TL-qD-pbO" customClass="EditTagsViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController"> <viewController storyboardIdentifier="EditTagsViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="3TL-qD-pbO" customClass="EditTagsViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="FH2-sj-H4t"> <view key="view" contentMode="scaleToFill" id="FH2-sj-H4t">
<rect key="frame" x="0.0" y="0.0" width="414" height="842"/> <rect key="frame" x="0.0" y="0.0" width="320" height="493"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <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="bb4-UL-VAQ"> <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="bb4-UL-VAQ">
<rect key="frame" x="16" y="110" width="382" height="682"/> <rect key="frame" x="16" y="124" width="288" height="353"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<prototypes> <prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="tagCell" id="c7T-0r-L5w" customClass="TagViewCell" customModule="Gallery" customModuleProvider="target"> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="tagCell" id="c7T-0r-L5w" customClass="TagViewCell" customModule="Gallery" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="382" height="47"/> <rect key="frame" x="0.0" y="28" width="288" height="44.5"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="c7T-0r-L5w" id="WjD-Nb-tif"> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="c7T-0r-L5w" id="WjD-Nb-tif">
<rect key="frame" x="0.0" y="0.0" width="382" height="47"/> <rect key="frame" x="0.0" y="0.0" width="288" height="44.5"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Cei-95-iOR"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Cei-95-iOR">
<rect key="frame" x="20" y="13" width="342" height="21"/> <rect key="frame" x="15" y="12" width="258" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
@ -200,13 +200,13 @@
</connections> </connections>
</tableView> </tableView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Tags" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Avc-oj-cgH"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Tags" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Avc-oj-cgH">
<rect key="frame" x="189" y="21" width="36.5" height="20"/> <rect key="frame" x="141" y="34" width="38" height="20"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Enter new tag..." textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="2po-UQ-V0K"> <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Enter new tag..." textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="2po-UQ-V0K">
<rect key="frame" x="16" y="60" width="382" height="34"/> <rect key="frame" x="16" y="74" width="288" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/> <fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="done"/> <textInputTraits key="textInputTraits" returnKeyType="done"/>
<connections> <connections>
@ -214,7 +214,7 @@
</connections> </connections>
</textField> </textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iWK-vF-Vze"> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iWK-vF-Vze">
<rect key="frame" x="16" y="15" width="30" height="30"/> <rect key="frame" x="16" y="28" width="30" height="31"/>
<state key="normal" title="Edit"/> <state key="normal" title="Edit"/>
<connections> <connections>
<action selector="editAction:" destination="3TL-qD-pbO" eventType="touchDown" id="5er-HM-8S2"/> <action selector="editAction:" destination="3TL-qD-pbO" eventType="touchDown" id="5er-HM-8S2"/>
@ -252,18 +252,18 @@
<objects> <objects>
<viewController storyboardIdentifier="InfoViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="MaR-nc-wxI" customClass="InfoViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController"> <viewController storyboardIdentifier="InfoViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="MaR-nc-wxI" customClass="InfoViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="VFL-0t-HSi"> <view key="view" contentMode="scaleToFill" id="VFL-0t-HSi">
<rect key="frame" x="0.0" y="0.0" width="414" height="842"/> <rect key="frame" x="0.0" y="0.0" width="320" height="493"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="yPq-yv-LyM"> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="yPq-yv-LyM">
<rect key="frame" x="361" y="15" width="37" height="30"/> <rect key="frame" x="266" y="28" width="38" height="30"/>
<state key="normal" title="Done"/> <state key="normal" title="Done"/>
<connections> <connections>
<action selector="exitAction:" destination="MaR-nc-wxI" eventType="touchDown" id="VYZ-ym-Qcz"/> <action selector="exitAction:" destination="MaR-nc-wxI" eventType="touchDown" id="VYZ-ym-Qcz"/>
</connections> </connections>
</button> </button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" numberOfLines="5" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="NDx-zx-hmw"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" numberOfLines="5" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="NDx-zx-hmw">
<rect key="frame" x="20" y="57" width="374" height="751"/> <rect key="frame" x="20" y="70" width="280" height="423"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
@ -294,11 +294,11 @@
<objects> <objects>
<viewController storyboardIdentifier="ReverseImageViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="VhH-X2-v6b" customClass="ReverseImageViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController"> <viewController storyboardIdentifier="ReverseImageViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="VhH-X2-v6b" customClass="ReverseImageViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="TNu-lY-cd3"> <view key="view" contentMode="scaleToFill" id="TNu-lY-cd3">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <rect key="frame" x="0.0" y="0.0" width="800" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<wkWebView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="uq3-56-0hX"> <wkWebView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="uq3-56-0hX">
<rect key="frame" x="0.0" y="102" width="414" height="760"/> <rect key="frame" x="0.0" y="59" width="800" height="541"/>
<color key="backgroundColor" red="0.36078431370000003" green="0.38823529410000002" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <color key="backgroundColor" red="0.36078431370000003" green="0.38823529410000002" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<wkWebViewConfiguration key="configuration"> <wkWebViewConfiguration key="configuration">
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/> <audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
@ -306,14 +306,14 @@
</wkWebViewConfiguration> </wkWebViewConfiguration>
</wkWebView> </wkWebView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rUi-3B-MYc"> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rUi-3B-MYc">
<rect key="frame" x="20" y="64" width="48" height="30"/> <rect key="frame" x="20" y="20" width="49" height="31"/>
<state key="normal" title="Cancel"/> <state key="normal" title="Cancel"/>
<connections> <connections>
<action selector="cancelAction:" destination="VhH-X2-v6b" eventType="touchDown" id="ggg-rw-euW"/> <action selector="cancelAction:" destination="VhH-X2-v6b" eventType="touchDown" id="ggg-rw-euW"/>
</connections> </connections>
</button> </button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dtc-GD-q7J"> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dtc-GD-q7J">
<rect key="frame" x="348" y="64" width="46" height="30"/> <rect key="frame" x="734" y="20" width="46" height="31"/>
<constraints> <constraints>
<constraint firstAttribute="width" constant="46" id="jzo-YK-PFI"/> <constraint firstAttribute="width" constant="46" id="jzo-YK-PFI"/>
</constraints> </constraints>
@ -346,11 +346,11 @@
<objects> <objects>
<viewController id="E6A-NM-9w9" customClass="SearchViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController"> <viewController id="E6A-NM-9w9" customClass="SearchViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="ZwQ-d4-u0T"> <view key="view" contentMode="scaleToFill" id="ZwQ-d4-u0T">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <rect key="frame" x="0.0" y="0.0" width="800" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="Bba-zG-RTo" customClass="PostCollectionView" customModule="Gallery" customModuleProvider="target"> <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="Bba-zG-RTo" customClass="PostCollectionView" customModule="Gallery" customModuleProvider="target">
<rect key="frame" x="0.0" y="140" width="414" height="722"/> <rect key="frame" x="0.0" y="102" width="800" height="498"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<collectionViewFlowLayout key="collectionViewLayout" automaticEstimatedItemSize="YES" minimumLineSpacing="10" minimumInteritemSpacing="10" id="aRU-y0-ffy"> <collectionViewFlowLayout key="collectionViewLayout" automaticEstimatedItemSize="YES" minimumLineSpacing="10" minimumInteritemSpacing="10" id="aRU-y0-ffy">
<size key="itemSize" width="50" height="50"/> <size key="itemSize" width="50" height="50"/>
@ -380,7 +380,7 @@
</cells> </cells>
</collectionView> </collectionView>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Search..." textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="hMR-QW-233"> <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Search..." textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="hMR-QW-233">
<rect key="frame" x="20" y="98" width="374" height="34"/> <rect key="frame" x="20" y="60" width="760" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/> <fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/> <textInputTraits key="textInputTraits"/>
<connections> <connections>
@ -415,11 +415,11 @@
<objects> <objects>
<viewController id="1Lq-DE-RSc" customClass="TagViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController"> <viewController id="1Lq-DE-RSc" customClass="TagViewController" customModule="Gallery" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="YEa-YJ-CTQ"> <view key="view" contentMode="scaleToFill" id="YEa-YJ-CTQ">
<rect key="frame" x="0.0" y="0.0" width="414" height="842"/> <rect key="frame" x="0.0" y="0.0" width="720" height="560"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="5op-NT-lmm" customClass="PostCollectionView" customModule="Gallery" customModuleProvider="target"> <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="5op-NT-lmm" customClass="PostCollectionView" customModule="Gallery" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="414" height="808"/> <rect key="frame" x="0.0" y="0.0" width="720" height="560"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<collectionViewFlowLayout key="collectionViewLayout" automaticEstimatedItemSize="YES" minimumLineSpacing="10" minimumInteritemSpacing="10" id="d7Y-hv-w27"> <collectionViewFlowLayout key="collectionViewLayout" automaticEstimatedItemSize="YES" minimumLineSpacing="10" minimumInteritemSpacing="10" id="d7Y-hv-w27">
<size key="itemSize" width="50" height="50"/> <size key="itemSize" width="50" height="50"/>
@ -471,7 +471,8 @@
<segue reference="s4Q-Cr-1uF"/> <segue reference="s4Q-Cr-1uF"/>
</inferredMetricsTieBreakers> </inferredMetricsTieBreakers>
<resources> <resources>
<image name="pencil" catalog="system" width="128" height="113"/> <image name="info.circle" catalog="system" width="128" height="121"/>
<image name="square.and.arrow.up" catalog="system" width="115" height="128"/> <image name="square.and.arrow.up" catalog="system" width="115" height="128"/>
<image name="tag" catalog="system" width="128" height="116"/>
</resources> </resources>
</document> </document>

View file

@ -46,7 +46,10 @@ func generateThumbnail(path: URL) -> UIImage? {
} }
} }
class PostCollectionView: UICollectionView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDropDelegate, UICollectionViewDragDelegate { class PostsManager: NSObject, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDropDelegate, UICollectionViewDragDelegate {
var collectionView : UICollectionView?
var managedContext: NSManagedObjectContext?
var posts: [NSManagedObject] = [] var posts: [NSManagedObject] = []
weak var viewController: UIViewController? weak var viewController: UIViewController?
@ -89,58 +92,64 @@ class PostCollectionView: UICollectionView, UICollectionViewDataSource, UICollec
return cell return cell
} }
func actualInit(tag: String?) { init(collectionView: UICollectionView, tag: String?) {
super.init()
self.collectionView = collectionView
collectionView.dragInteractionEnabled = true
collectionView.dataSource = self
collectionView.delegate = self
collectionView.dropDelegate = self
collectionView.dragDelegate = self
guard let appDelegate = guard let appDelegate =
UIApplication.shared.delegate as? AppDelegate else { UIApplication.shared.delegate as? AppDelegate else {
return return
} }
let managedContext = appDelegate.persistentContainer.viewContext managedContext = appDelegate.persistentContainer.viewContext
let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "Post")
if(tag != nil) {
let predicate = NSPredicate(format: "ANY tags.name in %@", [tag])
fetchRequest.predicate = predicate
}
setTag(tag: nil)
}
func reload(request: NSFetchRequest<NSManagedObject>) {
do { do {
posts = try managedContext.fetch(fetchRequest) posts = try managedContext!.fetch(request)
DispatchQueue.main.async { DispatchQueue.main.async {
self.reloadData() self.collectionView!.reloadData()
} }
} catch let error as NSError { } catch let error as NSError {
print("Could not fetch. \(error), \(error.userInfo)") print("Could not fetch. \(error), \(error.userInfo)")
} }
} }
override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) { func setTag(tag: String?) {
super.init(frame: frame, collectionViewLayout: layout) let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(managedObjectContextObjectsDidChange), name: NSNotification.Name.NSManagedObjectContextObjectsDidChange, object: managedContext)
self.dragInteractionEnabled = true let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "Post")
self.dataSource = self
self.delegate = self if(tag != nil) {
self.dropDelegate = self let predicate = NSPredicate(format: "ANY tags.name in %@", [tag])
self.dragDelegate = self
fetchRequest.predicate = predicate
}
reload(request: fetchRequest)
} }
required init?(coder: NSCoder) { @objc func managedObjectContextObjectsDidChange(notification: NSNotification) {
super.init(coder: coder) let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "Post")
reload(request: fetchRequest)
self.dragInteractionEnabled = true
self.dataSource = self
self.delegate = self
self.dropDelegate = self
self.dragDelegate = self
} }
func collectionView(_ collectionView: UICollectionView, func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout, layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize { sizeForItemAt indexPath: IndexPath) -> CGSize {
let paddingSpace = sectionInsets.left * (itemsPerRow + 1) let paddingSpace = sectionInsets.left * (itemsPerRow + 1)
let availableWidth = frame.width - paddingSpace let availableWidth = collectionView.frame.width - paddingSpace
let widthPerItem = availableWidth / itemsPerRow let widthPerItem = availableWidth / itemsPerRow
return CGSize(width: widthPerItem, height: widthPerItem) return CGSize(width: widthPerItem, height: widthPerItem)
@ -177,10 +186,10 @@ class PostCollectionView: UICollectionView, UICollectionViewDataSource, UICollec
let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { action in let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { action in
let index = self.posts.firstIndex(of: post) let index = self.posts.firstIndex(of: post)
let cell = self.cellForItem(at: IndexPath(row: index!, section: 0)) as! PostViewCell let cell = self.collectionView?.cellForItem(at: IndexPath(row: index!, section: 0)) as! PostViewCell
let imageSearch = ReverseImageSearchService() let imageSearch = ReverseImageSearchService()
imageSearch.viewController = self.window?.rootViewController imageSearch.viewController = self.collectionView?.window?.rootViewController
imageSearch.post = self.posts[index!] as? Post imageSearch.post = self.posts[index!] as? Post
let activityViewController = UIActivityViewController(activityItems: [cell.imageView.image!], applicationActivities: [imageSearch]) let activityViewController = UIActivityViewController(activityItems: [cell.imageView.image!], applicationActivities: [imageSearch])
@ -207,7 +216,7 @@ class PostCollectionView: UICollectionView, UICollectionViewDataSource, UICollec
let info = UIAction(title: "Info", image: UIImage(systemName: "info.circle")) { action in let info = UIAction(title: "Info", image: UIImage(systemName: "info.circle")) { action in
let index = self.posts.firstIndex(of: post) let index = self.posts.firstIndex(of: post)
let cell = self.cellForItem(at: IndexPath(row: index!, section: 0)) as! PostViewCell let cell = self.collectionView?.cellForItem(at: IndexPath(row: index!, section: 0)) as! PostViewCell
let viewController = InfoViewController.loadFromStoryboard() let viewController = InfoViewController.loadFromStoryboard()
viewController!.post = post as? Post viewController!.post = post as? Post
@ -230,7 +239,7 @@ class PostCollectionView: UICollectionView, UICollectionViewDataSource, UICollec
} }
DispatchQueue.main.async { DispatchQueue.main.async {
self.reloadData() self.collectionView?.reloadData()
} }
} }
@ -276,7 +285,7 @@ class PostCollectionView: UICollectionView, UICollectionViewDataSource, UICollec
try? managedContext.save() try? managedContext.save()
self.posts.append(post) self.posts.append(post)
self.reloadData() collectionView.reloadData()
} }
} }
} }
@ -291,7 +300,7 @@ class PostCollectionView: UICollectionView, UICollectionViewDataSource, UICollec
activity.userInfo = ["name": model.value(forKey: "name")!] activity.userInfo = ["name": model.value(forKey: "name")!]
activity.isEligibleForHandoff = true activity.isEligibleForHandoff = true
let itemProvider = NSItemProvider(object: (cellForItem(at: indexPath) as! PostViewCell).imageView.image!) let itemProvider = NSItemProvider(object: (collectionView.cellForItem(at: indexPath) as! PostViewCell).imageView.image!)
itemProvider.suggestedName = model.value(forKey: "name") as? String itemProvider.suggestedName = model.value(forKey: "name") as? String
itemProvider.registerObject(activity, visibility: .all) itemProvider.registerObject(activity, visibility: .all)

View file

@ -2,14 +2,16 @@ import UIKit
import CoreData import CoreData
class SearchViewController: UIViewController { class SearchViewController: UIViewController {
@IBOutlet weak var collectionView: PostCollectionView! @IBOutlet weak var collectionView: UICollectionView!
var postManager: PostsManager?
@IBOutlet weak var searchField: UITextField! @IBOutlet weak var searchField: UITextField!
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
collectionView.viewController = self postManager = PostsManager(collectionView: collectionView, tag: nil)
} }
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
@ -17,13 +19,13 @@ class SearchViewController: UIViewController {
let newViewController = segue.destination as! PostViewController let newViewController = segue.destination as! PostViewController
let index = self.collectionView.indexPathsForSelectedItems?.first let index = self.collectionView.indexPathsForSelectedItems?.first
newViewController.post = self.collectionView.posts[index!.row] newViewController.post = self.postManager?.posts[index!.row]
newViewController.image = (self.collectionView.cellForItem(at: index!) as! PostViewCell).imageView.image; newViewController.image = (self.collectionView.cellForItem(at: index!) as! PostViewCell).imageView.image;
} }
} }
@IBAction func searchAction(_ sender: Any) { @IBAction func searchAction(_ sender: Any) {
collectionView.actualInit(tag: searchField.text) postManager?.setTag(tag: searchField.text)
} }
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
@ -31,10 +33,10 @@ class SearchViewController: UIViewController {
#if targetEnvironment(macCatalyst) #if targetEnvironment(macCatalyst)
let index = self.collectionView.indexPathsForSelectedItems?.first let index = self.collectionView.indexPathsForSelectedItems?.first
let post = self.collectionView.posts[index!.row] let post = postManager?.posts[index!.row]
let activity = NSUserActivity(activityType: "post") let activity = NSUserActivity(activityType: "post")
activity.userInfo = ["name": post.value(forKey: "name") as! String] activity.userInfo = ["name": post?.value(forKey: "name") as! String]
activity.isEligibleForHandoff = true activity.isEligibleForHandoff = true
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: activity, options: nil, errorHandler: nil) UIApplication.shared.requestSceneSessionActivation(nil, userActivity: activity, options: nil, errorHandler: nil)

View file

@ -4,13 +4,20 @@ import CoreData
class TagViewController: UIViewController { class TagViewController: UIViewController {
var tag: String? var tag: String?
@IBOutlet weak var collectionView: PostCollectionView! var collectionManager: PostsManager?
@IBOutlet weak var collectionView: UICollectionView!
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
collectionView.actualInit(tag: self.tag) collectionManager = PostsManager(collectionView: collectionView, tag: nil)
collectionView.viewController = self }
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
collectionManager?.setTag(tag: self.tag)
} }
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
@ -18,7 +25,7 @@ class TagViewController: UIViewController {
let newViewController = segue.destination as! PostViewController let newViewController = segue.destination as! PostViewController
let index = self.collectionView.indexPathsForSelectedItems?.first let index = self.collectionView.indexPathsForSelectedItems?.first
newViewController.post = self.collectionView.posts[index!.row] newViewController.post = self.collectionManager?.posts[index!.row]
newViewController.image = (self.collectionView.cellForItem(at: index!) as! PostViewCell).imageView.image; newViewController.image = (self.collectionView.cellForItem(at: index!) as! PostViewCell).imageView.image;
} }
} }

View file

@ -2,7 +2,9 @@ import UIKit
import CoreData import CoreData
class ViewController: UIViewController, UIDocumentPickerDelegate { class ViewController: UIViewController, UIDocumentPickerDelegate {
@IBOutlet weak var collectionView: PostCollectionView! @IBOutlet weak var collectionView: UICollectionView!
var collectionManager: PostsManager?
let documentsPath : URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].absoluteURL let documentsPath : URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].absoluteURL
@ -24,6 +26,10 @@ class ViewController: UIViewController, UIDocumentPickerDelegate {
let newPath = documentsPath.appendingPathComponent(path.lastPathComponent) let newPath = documentsPath.appendingPathComponent(path.lastPathComponent)
do { do {
if FileManager.default.fileExists(atPath: newPath.path) {
try FileManager.default.removeItem(at: newPath)
}
try FileManager.default.copyItem(at: oldPath, to: newPath) try FileManager.default.copyItem(at: oldPath, to: newPath)
if let resourceValues = try? path.resourceValues(forKeys: [.typeIdentifierKey]), if let resourceValues = try? path.resourceValues(forKeys: [.typeIdentifierKey]),
@ -35,7 +41,7 @@ class ViewController: UIViewController, UIDocumentPickerDelegate {
post.setValue(path.lastPathComponent, forKeyPath: "name") post.setValue(path.lastPathComponent, forKeyPath: "name")
try managedContext.save() try managedContext.save()
collectionView.posts.append(post) collectionManager?.posts.append(post)
DispatchQueue.main.async { DispatchQueue.main.async {
self.collectionView.reloadData() self.collectionView.reloadData()
@ -48,8 +54,7 @@ class ViewController: UIViewController, UIDocumentPickerDelegate {
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
collectionView.actualInit(tag: nil) collectionManager = PostsManager(collectionView: collectionView, tag: nil)
collectionView.viewController = self
} }
override func viewDidAppear(_ animated: Bool) { override func viewDidAppear(_ animated: Bool) {
@ -77,7 +82,7 @@ class ViewController: UIViewController, UIDocumentPickerDelegate {
let newViewController = segue.destination as! PostViewController let newViewController = segue.destination as! PostViewController
let index = self.collectionView.indexPathsForSelectedItems?.first let index = self.collectionView.indexPathsForSelectedItems?.first
newViewController.post = self.collectionView.posts[index!.row] newViewController.post = self.collectionManager?.posts[index!.row]
newViewController.image = (self.collectionView.cellForItem(at: index!) as! PostViewCell).imageView.image; newViewController.image = (self.collectionView.cellForItem(at: index!) as! PostViewCell).imageView.image;
} }
} }