From cc5f39b36a20730d07fad1287007195bc1be1c7d Mon Sep 17 00:00:00 2001 From: longitachi Date: Wed, 6 Mar 2024 15:04:13 +0800 Subject: [PATCH] fix #892 --- Package.swift | 6 ++- Sources/General/ZLWeakProxy.swift | 52 ++++++++++++++++++++++++ ZLPhotoBrowser.xcodeproj/project.pbxproj | 4 ++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 Sources/General/ZLWeakProxy.swift diff --git a/Package.swift b/Package.swift index cb4ab2de..77a21486 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,11 @@ let package = Package( .target( name: "ZLPhotoBrowser", path: "Sources", - exclude: ["Info.plist"], + exclude: [ + "Info.plist", + "General/ZLWeakProxy.h", + "General/ZLWeakProxy.m" + ], resources: [ .process("ZLPhotoBrowser.bundle") ] diff --git a/Sources/General/ZLWeakProxy.swift b/Sources/General/ZLWeakProxy.swift new file mode 100644 index 00000000..f39cf464 --- /dev/null +++ b/Sources/General/ZLWeakProxy.swift @@ -0,0 +1,52 @@ +// +// ZLWeakProxy.swift +// ZLPhotoBrowser +// +// Created by long on 2024/3/6. +// +// Copyright (c) 2020 Long Zhang <495181165@qq.com> +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#if SWIFT_PACKAGE + +import UIKit + +class ZLWeakProxy: NSObject { + private weak var target: NSObjectProtocol? + + init(target: NSObjectProtocol) { + self.target = target + super.init() + } + + class func proxy(target: NSObjectProtocol) -> ZLWeakProxy { + return ZLWeakProxy(target: target) + } + + override func forwardingTarget(for aSelector: Selector!) -> Any? { + return target + } + + override func responds(to aSelector: Selector!) -> Bool { + return target?.responds(to: aSelector) ?? false + } +} + +#endif diff --git a/ZLPhotoBrowser.xcodeproj/project.pbxproj b/ZLPhotoBrowser.xcodeproj/project.pbxproj index 4c796fc6..3a6cf4c9 100644 --- a/ZLPhotoBrowser.xcodeproj/project.pbxproj +++ b/ZLPhotoBrowser.xcodeproj/project.pbxproj @@ -62,6 +62,7 @@ FD21E4E1272FFE8E00D1D168 /* ZLPhotoConfiguration+Chaining.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD21E4E0272FFE8E00D1D168 /* ZLPhotoConfiguration+Chaining.swift */; }; FD24655828E2A96200C15B20 /* UIView+ZLPhotoBrowser.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD24655728E2A96200C15B20 /* UIView+ZLPhotoBrowser.swift */; }; FD34FC622AD25A2100AE4344 /* UIScrollView+ZLPhotoBrowser.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD34FC612AD25A2100AE4344 /* UIScrollView+ZLPhotoBrowser.swift */; }; + FD3B66982B984BB0009C7353 /* ZLWeakProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD3B66972B984BB0009C7353 /* ZLWeakProxy.swift */; }; FD4C971B29F11918000249BF /* ZLCollectionViewFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD4C971A29F11918000249BF /* ZLCollectionViewFlowLayout.swift */; }; FD5230B5281562DD0034B782 /* ZLEnlargeButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD5230B4281562DD0034B782 /* ZLEnlargeButton.swift */; }; FD74F6DD29345E4100B7916A /* ZLBaseStickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD74F6DC29345E4100B7916A /* ZLBaseStickerView.swift */; }; @@ -137,6 +138,7 @@ FD21E4E0272FFE8E00D1D168 /* ZLPhotoConfiguration+Chaining.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ZLPhotoConfiguration+Chaining.swift"; sourceTree = ""; }; FD24655728E2A96200C15B20 /* UIView+ZLPhotoBrowser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+ZLPhotoBrowser.swift"; sourceTree = ""; }; FD34FC612AD25A2100AE4344 /* UIScrollView+ZLPhotoBrowser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIScrollView+ZLPhotoBrowser.swift"; sourceTree = ""; }; + FD3B66972B984BB0009C7353 /* ZLWeakProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZLWeakProxy.swift; sourceTree = ""; }; FD4C971A29F11918000249BF /* ZLCollectionViewFlowLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLCollectionViewFlowLayout.swift; sourceTree = ""; }; FD5230B4281562DD0034B782 /* ZLEnlargeButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLEnlargeButton.swift; sourceTree = ""; }; FD74F6DC29345E4100B7916A /* ZLBaseStickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLBaseStickerView.swift; sourceTree = ""; }; @@ -276,6 +278,7 @@ FDAE00A8297134C100EE9486 /* ZLAnimationUtils.swift */, FDCBAF9F2B1ED0A9000860FD /* ZLWeakProxy.h */, FDCBAF9E2B1ED0A9000860FD /* ZLWeakProxy.m */, + FD3B66972B984BB0009C7353 /* ZLWeakProxy.swift */, ); path = General; sourceTree = ""; @@ -399,6 +402,7 @@ FD24655828E2A96200C15B20 /* UIView+ZLPhotoBrowser.swift in Sources */, E4943ABB255A652A00C29B3A /* CGFloat+ZLPhotoBrowser.swift in Sources */, FDC8ED0B2B0F4032002EB8B9 /* UIGraphicsImageRenderer+ZLPhotoBrowser.swift in Sources */, + FD3B66982B984BB0009C7353 /* ZLWeakProxy.swift in Sources */, E4765DFB25415F87007B2C0F /* ZLImagePreviewController.swift in Sources */, FDB34114280D0D70008F20B3 /* ZLPhotoUIConfiguration.swift in Sources */, E466804724FB76C50011E332 /* ZLEditVideoViewController.swift in Sources */,