From 85bbf028cfbe4eb9faddd1df86319cff3e0d47d6 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 19 Mar 2019 13:11:05 -0400 Subject: [PATCH] Loadimageview to swift --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 8 ++++++++ .../Categories/NSNumber+Extension.swift | 15 +++++++++++++++ MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h | 8 ++++---- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m | 10 +++++----- .../MVMCoreGetterUtility+Extension.swift | 19 +++++++++++++++++++ 5 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 MVMCore/MVMCore/Categories/NSNumber+Extension.swift create mode 100644 MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility+Extension.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 276a6b4..0fbab87 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -140,6 +140,8 @@ AFFCFA661FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = AFFCFA621FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; AFFCFA671FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = AFFCFA631FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.m */; }; AFFCFA681FCCC0D700FD0730 /* MVMCoreLoadingViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; + D282AAB62240085300C46919 /* MVMCoreGetterUtility+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */; }; + D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB72240342D00C46919 /* NSNumber+Extension.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -270,6 +272,8 @@ AFFCFA621FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoadingOverlayHandler.h; sourceTree = ""; }; AFFCFA631FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreLoadingOverlayHandler.m; sourceTree = ""; }; AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoadingViewControllerProtocol.h; sourceTree = ""; }; + D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreGetterUtility+Extension.swift"; sourceTree = ""; }; + D282AAB72240342D00C46919 /* NSNumber+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSNumber+Extension.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -342,6 +346,7 @@ isa = PBXGroup; children = ( 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */, + D282AAB72240342D00C46919 /* NSNumber+Extension.swift */, 8876D5DA1FB50AB000EB2E3D /* NSArray+MFConvenience.h */, 8876D5DB1FB50AB000EB2E3D /* NSArray+MFConvenience.m */, 8876D5DC1FB50AB000EB2E3D /* NSDecimalNumber+MFConvenience.h */, @@ -515,6 +520,7 @@ AFBB96AD1FBA3B590008D868 /* MVMCoreDispatchUtility.m */, AFBB96AE1FBA3B590008D868 /* MVMCoreGetterUtility.h */, AFBB96AF1FBA3B590008D868 /* MVMCoreGetterUtility.m */, + D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */, AF43A5851FBB67D6008E9347 /* MVMCoreActionUtility.h */, AF43A5861FBB67D6008E9347 /* MVMCoreActionUtility.m */, ); @@ -768,6 +774,7 @@ AFBB96BA1FBA3CEC0008D868 /* MVMCoreActionHandler.m in Sources */, AFBB96ED1FBA4A260008D868 /* MFHardCodedServerResponse.m in Sources */, AF43A74D1FC6109F008E9347 /* MVMCoreSessionObject.m in Sources */, + D282AAB62240085300C46919 /* MVMCoreGetterUtility+Extension.swift in Sources */, AFBB965F1FBA3A570008D868 /* MFFreebeeOperation.m in Sources */, AFBB96901FBA3A9A0008D868 /* MVMCoreNavigationObject.m in Sources */, AFBB96A61FBA3A9A0008D868 /* MVMCoreTopAlertOperation.m in Sources */, @@ -804,6 +811,7 @@ AF43A5841FBB66DE008E9347 /* MVMCoreConstants.m in Sources */, AFBB966A1FBA3A570008D868 /* MVMCoreLoadRequestOperation.m in Sources */, 8876D5F31FB50AB000EB2E3D /* UIFont+MFSpacing.m in Sources */, + D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MVMCore/MVMCore/Categories/NSNumber+Extension.swift b/MVMCore/MVMCore/Categories/NSNumber+Extension.swift new file mode 100644 index 0000000..d2621bc --- /dev/null +++ b/MVMCore/MVMCore/Categories/NSNumber+Extension.swift @@ -0,0 +1,15 @@ +// +// NSNumber+Extension.swift +// MVMCore +// +// Created by Scott Pfeil on 3/18/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +public extension NSNumber { + public func cgfloat() -> CGFloat { + return CGFloat(doubleValue) + } +} diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h index a60d0ef..6d7d5a9 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h @@ -118,12 +118,12 @@ typedef void(^MVMCoreGetImageBlock)(UIImage * _Nullable, NSData * _Nullable, BOO // Most cases only need to provide the width. If both are provided and the aspect ratio is different from the images, it will center the image. // In the future, may need to use align for the shop flow. // localFallbackImageName: should be the name of a local file to use in case of failure to download. -- (void)getImage:(nonnull NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; -- (void)getImage:(nonnull NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; -- (void)getGif:(nonnull NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; +- (void)getImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; +- (void)getImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; +- (void)getGif:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; // Gets a cropped version of the requested image. Similar to the method above, but you can specify the final rect -- (void)getCroppedImage:(nonnull NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 finalRect:(CGRect)finalRect flipImage:(BOOL)flipImage localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; +- (void)getCroppedImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 finalRect:(CGRect)finalRect flipImage:(BOOL)flipImage localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; // Gets an image from the cache. - (nullable UIImage *)getCachedImageWithName:(nonnull NSString *)imageName; diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index 73428c4..7e12a81 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -453,15 +453,15 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; return [components URL]; } -- (void)getImage:(nonnull NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { +- (void)getImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { [self getImage:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:nil localFallbackImageName:fallbackImageName completionHandler:completionHandler]; } -- (void)getImage:(nonnull NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { +- (void)getImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { [self getImage:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:CGRectNull flipImage:NO localFallbackImageName:fallbackImageName completionHandler:completionHandler]; } -- (void)getGif:(nonnull NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { +- (void)getGif:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData *imageData = nil; @@ -488,12 +488,12 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; }); } -- (void)getCroppedImage:(nonnull NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 finalRect:(CGRect)finalRect flipImage:(BOOL)flip localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { +- (void)getCroppedImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 finalRect:(CGRect)finalRect flipImage:(BOOL)flip localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { [self getImage:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:nil finalRect:finalRect flipImage:flip localFallbackImageName:fallbackImageName completionHandler:completionHandler]; } -- (void)getImage:(nonnull NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format finalRect:(CGRect)finalRect flipImage:(BOOL)flip localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { +- (void)getImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format finalRect:(CGRect)finalRect flipImage:(BOOL)flip localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ UIImage *image = nil; if (pathOrName.length > 0) { diff --git a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility+Extension.swift b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility+Extension.swift new file mode 100644 index 0000000..835c0fb --- /dev/null +++ b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility+Extension.swift @@ -0,0 +1,19 @@ +// +// MVMCoreGetterUtility+Extension.swift +// MVMCore +// +// Created by Scott Pfeil on 3/18/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +public extension MVMCoreGetterUtility { + public class func fequal(a: Float ,b: Float) -> Bool { + return (abs((a) - (b)) < Float.ulpOfOne) + } + + public class func cgfequal(_ a: CGFloat ,_ b: CGFloat) -> Bool { + return (abs((a) - (b)) < CGFloat.ulpOfOne) + } +}