Skip to content

Commit

Permalink
Using OC to implement ZLWeakProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
longitachi committed Dec 5, 2023
1 parent 44f54bb commit b438ec3
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Sources/Edit/ZLEditImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ open class ZLEditImageViewController: UIViewController {
angle: currentClipStatus.angle,
editRect: currentClipStatus.editRect,
isCircle: currentClipStatus.ratio?.isCircle ?? false
) ?? resImage
)
editModel = ZLEditImageModel(
drawPaths: drawPaths,
mosaicPaths: mosaicPaths,
Expand Down
1 change: 0 additions & 1 deletion Sources/General/ZLPhotoPreviewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ class ZLPhotoPreviewController: UIViewController {
}

let config = ZLPhotoConfiguration.default()
let uiConfig = ZLPhotoUIConfiguration.default()
let currentModel = arrDataSources[currentIndex]

if (!config.allowMixSelect && currentModel.type == .video) ||
Expand Down
38 changes: 15 additions & 23 deletions Sources/General/ZLWeakProxy.swift → Sources/General/ZLWeakProxy.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// ZLWeakProxy.swift
// ZLWeakProxy.h
// ZLPhotoBrowser
//
// Created by long on 2021/3/10.
// Created by long on 2023/12/5.
//
// Copyright (c) 2020 Long Zhang <[email protected]>
//
Expand All @@ -24,25 +24,17 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import UIKit
#import <Foundation/Foundation.h>

class ZLWeakProxy: NSObject {
private weak var target: NSObjectProtocol?

init(target: NSObjectProtocol) {
self.target = target
super.init()
}

class func proxy(withTarget 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
}
}
NS_ASSUME_NONNULL_BEGIN

@interface ZLWeakProxy : NSObject

@property (nonatomic, weak, readonly, nullable) id target;

- (nonnull instancetype)initWithTarget:(nonnull id)target NS_SWIFT_NAME(init(target:));
+ (nonnull instancetype)proxyWithTarget:(nonnull id)target NS_SWIFT_NAME(proxy(target:));

@end

NS_ASSUME_NONNULL_END
53 changes: 53 additions & 0 deletions Sources/General/ZLWeakProxy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// ZLWeakProxy.m
// ZLPhotoBrowser
//
// Created by long on 2023/12/5.
//
// Copyright (c) 2020 Long Zhang <[email protected]>
//
// 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.

#import "ZLWeakProxy.h"

@implementation ZLWeakProxy

- (instancetype)initWithTarget:(id)target {
_target = target;
return self;
}

+ (instancetype)proxyWithTarget:(id)target {
return [[ZLWeakProxy alloc] initWithTarget:target];
}

- (id)forwardingTargetForSelector:(SEL)selector {
return _target;
}

- (void)forwardInvocation:(NSInvocation *)invocation {
void *null = NULL;
[invocation setReturnValue:&null];
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
return [NSObject instanceMethodSignatureForSelector:@selector(init)];
}

@end
3 changes: 1 addition & 2 deletions Sources/ZLPhotoBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// THE SOFTWARE.

#import <Foundation/Foundation.h>
#import <ZLPhotoBrowser/ZLWeakProxy.h>

//! Project version number for ZLPhotoBrowser.
FOUNDATION_EXPORT double ZLPhotoBrowserVersionNumber;
Expand All @@ -33,5 +34,3 @@ FOUNDATION_EXPORT double ZLPhotoBrowserVersionNumber;
FOUNDATION_EXPORT const unsigned char ZLPhotoBrowserVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <ZLPhotoBrowser/PublicHeader.h>


2 changes: 1 addition & 1 deletion ZLPhotoBrowser.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Pod::Spec.new do |s|
s.resources = 'Sources/*.{png,bundle}'

s.subspec "Core" do |sp|
sp.source_files = ["Sources/**/*.swift", "Sources/ZLPhotoBrowser.h"]
sp.source_files = ["Sources/**/*.{swift,h,m}", "Sources/ZLPhotoBrowser.h"]
end

end
14 changes: 9 additions & 5 deletions ZLPhotoBrowser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
E466804724FB76C50011E332 /* ZLEditVideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E466804624FB76C50011E332 /* ZLEditVideoViewController.swift */; };
E46EA7D824F79F1C00033853 /* ZLClipImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E46EA7D724F79F1C00033853 /* ZLClipImageViewController.swift */; };
E4765DFB25415F87007B2C0F /* ZLImagePreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4765DFA25415F87007B2C0F /* ZLImagePreviewController.swift */; };
E48CE1C525F89EC900D31452 /* ZLWeakProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = E48CE1C425F89EC900D31452 /* ZLWeakProxy.swift */; };
E48E52D52507297500619AED /* ZLClipImageDismissAnimatedTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = E48E52D42507297500619AED /* ZLClipImageDismissAnimatedTransition.swift */; };
E492ABEB24E53575005E1BD5 /* Cell+ZLPhotoBrowser.swift in Sources */ = {isa = PBXBuildFile; fileRef = E492ABEA24E53575005E1BD5 /* Cell+ZLPhotoBrowser.swift */; };
E492ABED24E5454E005E1BD5 /* ZLProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E492ABEC24E5454E005E1BD5 /* ZLProgressView.swift */; };
Expand Down Expand Up @@ -73,6 +72,8 @@
FDB34268280E6566008F20B3 /* ZLPhotoUIConfiguration+Chaining.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB34267280E6566008F20B3 /* ZLPhotoUIConfiguration+Chaining.swift */; };
FDC6B5FD273B6E1C00973E43 /* ZLCameraConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC6B5FC273B6E1C00973E43 /* ZLCameraConfiguration.swift */; };
FDC8ED0B2B0F4032002EB8B9 /* UIGraphicsImageRenderer+ZLPhotoBrowser.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC8ED0A2B0F4032002EB8B9 /* UIGraphicsImageRenderer+ZLPhotoBrowser.swift */; };
FDCBAFA02B1ED0A9000860FD /* ZLWeakProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = FDCBAF9E2B1ED0A9000860FD /* ZLWeakProxy.m */; };
FDCBAFA12B1ED0A9000860FD /* ZLWeakProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = FDCBAF9F2B1ED0A9000860FD /* ZLWeakProxy.h */; settings = {ATTRIBUTES = (Public, ); }; };
FDE1DB76289A4B120003CA4D /* NSError+ZLPhotoBrowser.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE1DB75289A4B120003CA4D /* NSError+ZLPhotoBrowser.swift */; };
FDE374252AC1AE3700BA7DA0 /* ZLPaths.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE374242AC1AE3700BA7DA0 /* ZLPaths.swift */; };
FDF7790B2AC1700F00001015 /* ZLEditorManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF7790A2AC1700F00001015 /* ZLEditorManager.swift */; };
Expand Down Expand Up @@ -102,7 +103,6 @@
E466804624FB76C50011E332 /* ZLEditVideoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLEditVideoViewController.swift; sourceTree = "<group>"; };
E46EA7D724F79F1C00033853 /* ZLClipImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLClipImageViewController.swift; sourceTree = "<group>"; };
E4765DFA25415F87007B2C0F /* ZLImagePreviewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLImagePreviewController.swift; sourceTree = "<group>"; };
E48CE1C425F89EC900D31452 /* ZLWeakProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLWeakProxy.swift; sourceTree = "<group>"; };
E48E52D42507297500619AED /* ZLClipImageDismissAnimatedTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLClipImageDismissAnimatedTransition.swift; sourceTree = "<group>"; };
E492ABEA24E53575005E1BD5 /* Cell+ZLPhotoBrowser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Cell+ZLPhotoBrowser.swift"; sourceTree = "<group>"; };
E492ABEC24E5454E005E1BD5 /* ZLProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLProgressView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -147,6 +147,8 @@
FDB34267280E6566008F20B3 /* ZLPhotoUIConfiguration+Chaining.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ZLPhotoUIConfiguration+Chaining.swift"; sourceTree = "<group>"; };
FDC6B5FC273B6E1C00973E43 /* ZLCameraConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLCameraConfiguration.swift; sourceTree = "<group>"; };
FDC8ED0A2B0F4032002EB8B9 /* UIGraphicsImageRenderer+ZLPhotoBrowser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIGraphicsImageRenderer+ZLPhotoBrowser.swift"; sourceTree = "<group>"; };
FDCBAF9E2B1ED0A9000860FD /* ZLWeakProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZLWeakProxy.m; sourceTree = "<group>"; };
FDCBAF9F2B1ED0A9000860FD /* ZLWeakProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZLWeakProxy.h; sourceTree = "<group>"; };
FDE1DB75289A4B120003CA4D /* NSError+ZLPhotoBrowser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSError+ZLPhotoBrowser.swift"; sourceTree = "<group>"; };
FDE374242AC1AE3700BA7DA0 /* ZLPaths.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLPaths.swift; sourceTree = "<group>"; };
FDF7790A2AC1700F00001015 /* ZLEditorManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLEditorManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -272,7 +274,8 @@
E40ECF4724FFB8BB00A4D923 /* ZLPhotoBrowser.swift */,
FD8FEA6628C8B9B60041374B /* ZLResultModel.swift */,
FDAE00A8297134C100EE9486 /* ZLAnimationUtils.swift */,
E48CE1C425F89EC900D31452 /* ZLWeakProxy.swift */,
FDCBAF9F2B1ED0A9000860FD /* ZLWeakProxy.h */,
FDCBAF9E2B1ED0A9000860FD /* ZLWeakProxy.m */,
);
path = General;
sourceTree = "<group>";
Expand Down Expand Up @@ -313,6 +316,7 @@
buildActionMask = 2147483647;
files = (
E4C911C524E284B30061DA40 /* ZLPhotoBrowser.h in Headers */,
FDCBAFA12B1ED0A9000860FD /* ZLWeakProxy.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -347,7 +351,7 @@
TargetAttributes = {
E4C911BF24E284B30061DA40 = {
CreatedOnToolsVersion = 12.0;
LastSwiftMigration = 1210;
LastSwiftMigration = 1500;
};
};
};
Expand Down Expand Up @@ -388,7 +392,6 @@
E4A9CE012505DB91003201C1 /* ZLEmbedAlbumListView.swift in Sources */,
E48E52D52507297500619AED /* ZLClipImageDismissAnimatedTransition.swift in Sources */,
FD5230B5281562DD0034B782 /* ZLEnlargeButton.swift in Sources */,
E48CE1C525F89EC900D31452 /* ZLWeakProxy.swift in Sources */,
E4C911D224E2884E0061DA40 /* ZLPhotoPreviewSheet.swift in Sources */,
E46EA7D824F79F1C00033853 /* ZLClipImageViewController.swift in Sources */,
E4C911E024E2ACE20061DA40 /* ZLPhotoManager.swift in Sources */,
Expand Down Expand Up @@ -426,6 +429,7 @@
FDAE00A9297134C100EE9486 /* ZLAnimationUtils.swift in Sources */,
FD4C971B29F11918000249BF /* ZLCollectionViewFlowLayout.swift in Sources */,
E49BD1FB24E3D515005D7DFB /* Bundle+ZLPhotoBrowser.swift in Sources */,
FDCBAFA02B1ED0A9000860FD /* ZLWeakProxy.m in Sources */,
FD201F3F286C7D9B005C6B53 /* ZLCustomAlertProtocol.swift in Sources */,
E4D046F02500A341000BAEC2 /* ZLPhotoPreviewAnimatedTransition.swift in Sources */,
FDB34268280E6566008F20B3 /* ZLPhotoUIConfiguration+Chaining.swift in Sources */,
Expand Down

0 comments on commit b438ec3

Please sign in to comment.