From 79c11ff75a6823b6863781c34093455d5dbfedad Mon Sep 17 00:00:00 2001 From: Ricardo Santos Date: Mon, 21 Aug 2017 14:57:05 +0930 Subject: [PATCH 01/10] Add a method to generate a random string --- NFAllocInit/Categories/NSString+NFAllocInit.h | 2 ++ NFAllocInit/Categories/NSString+NFAllocInit.m | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/NFAllocInit/Categories/NSString+NFAllocInit.h b/NFAllocInit/Categories/NSString+NFAllocInit.h index 6d1bc1c..d3be553 100644 --- a/NFAllocInit/Categories/NSString+NFAllocInit.h +++ b/NFAllocInit/Categories/NSString+NFAllocInit.h @@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN - (NSString *)trim; - (NSArray *)matchesForRegex:(NSString *)regex options:(NSRegularExpressionOptions)options; ++ (NSString *)randomAlphanumericStringWithLength:(NSInteger)length; + @end NS_ASSUME_NONNULL_END diff --git a/NFAllocInit/Categories/NSString+NFAllocInit.m b/NFAllocInit/Categories/NSString+NFAllocInit.m index 3fb25aa..e123bc8 100644 --- a/NFAllocInit/Categories/NSString+NFAllocInit.m +++ b/NFAllocInit/Categories/NSString+NFAllocInit.m @@ -59,4 +59,17 @@ - (NSString *)trim { return [NSArray array]; } ++ (NSString *)randomAlphanumericStringWithLength:(NSInteger)length { + // https://stackoverflow.com/a/2633948/883413 + + NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + NSMutableString *randomString = [NSMutableString stringWithCapacity:length]; + + for (int i = 0; i < length; i++) { + [randomString appendFormat:@"%C", [letters characterAtIndex:arc4random() % [letters length]]]; + } + + return randomString; +} + @end From 636f3af25a6b4bda0bd50d13811e9a2b99bace87 Mon Sep 17 00:00:00 2001 From: Ric Santos Date: Mon, 28 Aug 2017 16:55:01 +0930 Subject: [PATCH 02/10] Fix dateFromString to set a timezone to match stringFromDate --- NFAllocInit/NFDateUtils.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/NFAllocInit/NFDateUtils.m b/NFAllocInit/NFDateUtils.m index f735d21..1fec816 100644 --- a/NFAllocInit/NFDateUtils.m +++ b/NFAllocInit/NFDateUtils.m @@ -43,7 +43,6 @@ + (NSString *)stringFromTimeInterval:(NSTimeInterval)timeInterval return string; } - + (NSString *)stringFromDate:(NSDate *)date { return [NFDateUtils stringFromDate:date withFormat:NFDateFormatISO_8601]; @@ -85,6 +84,10 @@ + (NSDate *)dateFromString:(NSString *)string withFormat:(NSString *)dateFormat { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = dateFormat; + + NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0]; + [formatter setTimeZone:timeZone]; + NSDate *date = [formatter dateFromString:string]; return date; } From 128e59e870c5b2636811dd65f9bceb0e21ebe423 Mon Sep 17 00:00:00 2001 From: Ricardo Santos Date: Wed, 13 Sep 2017 14:03:57 +0930 Subject: [PATCH 03/10] Add milliseconds to ISO-8601 date format --- NFAllocInit/NFDateUtils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NFAllocInit/NFDateUtils.h b/NFAllocInit/NFDateUtils.h index 40131c7..22411a5 100644 --- a/NFAllocInit/NFDateUtils.h +++ b/NFAllocInit/NFDateUtils.h @@ -8,7 +8,7 @@ #import -#define NFDateFormatISO_8601 @"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'" +#define NFDateFormatISO_8601 @"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'" #define NFDateFormatStandard @"yyyy-MM-dd hh:mm:ss a" NS_ASSUME_NONNULL_BEGIN From 95eb5feb5abd7e94a2c2c51138272b3653e5478e Mon Sep 17 00:00:00 2001 From: Ricardo Santos Date: Wed, 1 Nov 2017 14:05:44 +1030 Subject: [PATCH 04/10] Add a size to fit with ceiling method to UIView --- NFAllocInit/Categories/UIView+NFAllocInit.h | 1 + NFAllocInit/Categories/UIView+NFAllocInit.m | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/NFAllocInit/Categories/UIView+NFAllocInit.h b/NFAllocInit/Categories/UIView+NFAllocInit.h index 651310b..bc5435c 100644 --- a/NFAllocInit/Categories/UIView+NFAllocInit.h +++ b/NFAllocInit/Categories/UIView+NFAllocInit.h @@ -11,5 +11,6 @@ - (void)printAllSubviews; - (nullable UIViewController *)findViewController; +- (void)sizeToFitCeiling; @end diff --git a/NFAllocInit/Categories/UIView+NFAllocInit.m b/NFAllocInit/Categories/UIView+NFAllocInit.m index 8de8587..f4556ba 100644 --- a/NFAllocInit/Categories/UIView+NFAllocInit.m +++ b/NFAllocInit/Categories/UIView+NFAllocInit.m @@ -41,5 +41,9 @@ - (UIViewController*)findViewController return nil; } +- (void)sizeToFitCeiling { + CGSize size = [self sizeThatFits:self.bounds.size]; + self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, ceilf(size.width), ceilf(size.height)); +} @end From e88e1d5ad73dadffea2aa470922d039f556cef4b Mon Sep 17 00:00:00 2001 From: Ricardo Santos Date: Tue, 17 Jul 2018 17:03:56 +0930 Subject: [PATCH 05/10] Add Xcode generated file --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 NFAllocInit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/NFAllocInit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/NFAllocInit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/NFAllocInit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 16884e53d8ed20f132b03702e3adcf1d855a0e55 Mon Sep 17 00:00:00 2001 From: Ricardo Santos Date: Tue, 17 Jul 2018 17:04:37 +0930 Subject: [PATCH 06/10] Fix string from time interval to treat interval as seconds --- NFAllocInit/NFDateUtils.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/NFAllocInit/NFDateUtils.m b/NFAllocInit/NFDateUtils.m index 1fec816..c59de7a 100644 --- a/NFAllocInit/NFDateUtils.m +++ b/NFAllocInit/NFDateUtils.m @@ -20,9 +20,8 @@ + (NSString *)stringForValue:(NSUInteger)value withNonPluralUnit:(NSString *)uni + (NSString *)stringFromTimeInterval:(NSTimeInterval)timeInterval { - NSUInteger time = (NSUInteger)timeInterval; - NSUInteger seconds = time % 60; - NSUInteger minutes = time / 60; + NSUInteger seconds = (NSUInteger)timeInterval; + NSUInteger minutes = seconds / 60; NSUInteger hours = minutes / 60; NSUInteger days = hours / 24; NSUInteger weeks = days / 7; From 6fbee14aba04581711e801acb9fc892d7db15378 Mon Sep 17 00:00:00 2001 From: Ricardo Santos Date: Tue, 17 Jul 2018 17:06:01 +0930 Subject: [PATCH 07/10] Add function to convert a time interval (seconds) to a hh:mm:ss string --- NFAllocInit/NFDateUtils.h | 7 +++++++ NFAllocInit/NFDateUtils.m | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/NFAllocInit/NFDateUtils.h b/NFAllocInit/NFDateUtils.h index 22411a5..1e222a3 100644 --- a/NFAllocInit/NFDateUtils.h +++ b/NFAllocInit/NFDateUtils.h @@ -15,7 +15,14 @@ NS_ASSUME_NONNULL_BEGIN @interface NFDateUtils : NSObject +typedef NS_OPTIONS(NSUInteger, TimeUnitOptions) { + TimeUnitSeconds = 1 << 0, + TimeUnitMinutes = 1 << 1, + TimeUnitHours = 1 << 2, +}; + + (NSString *)stringFromTimeInterval:(NSTimeInterval)timeInterval; ++ (NSString *)isoStyleStringFromTimeInterval:(NSTimeInterval)timeInterval displayingTimeUnitOptions:(TimeUnitOptions)timeUnitOptions; + (NSString *)stringFromDate:(NSDate *)date; + (NSString *)stringFromDate:(NSDate *)date withStyle:(NSDateFormatterStyle)style; diff --git a/NFAllocInit/NFDateUtils.m b/NFAllocInit/NFDateUtils.m index c59de7a..d8671bf 100644 --- a/NFAllocInit/NFDateUtils.m +++ b/NFAllocInit/NFDateUtils.m @@ -47,6 +47,33 @@ + (NSString *)stringFromDate:(NSDate *)date return [NFDateUtils stringFromDate:date withFormat:NFDateFormatISO_8601]; } ++ (NSString *)isoStyleStringFromTimeInterval:(NSTimeInterval)timeInterval displayingTimeUnitOptions:(TimeUnitOptions)timeUnitOptions +{ + NSUInteger time = (NSUInteger)timeInterval; + NSUInteger hours = time / 3600; + NSUInteger minutes = (time / 60) % 60; + NSUInteger seconds = time % 60; + + NSString *string = @""; + if (timeUnitOptions & TimeUnitHours) { + string = [string stringByAppendingFormat:@"%lu", hours]; + } + if (timeUnitOptions & TimeUnitMinutes) { + if (string.length > 0) { + string = [string stringByAppendingString:@":"]; + } + string = [string stringByAppendingFormat:@"%ld", minutes]; + } + if (timeUnitOptions & TimeUnitSeconds) { + if (string.length > 0) { + string = [string stringByAppendingString:@":"]; + } + string = [string stringByAppendingFormat:@"%ld", seconds]; + } + + return string; +} + + (NSString *)stringFromDate:(NSDate *)date withStyle:(NSDateFormatterStyle)style { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; From 52167318852d47cf4e21d4b7885b78250290030f Mon Sep 17 00:00:00 2001 From: Ricardo Santos Date: Fri, 20 Jul 2018 12:35:20 +0930 Subject: [PATCH 08/10] Add leading zeros to hh:mm:ss formatter --- NFAllocInit/NFDateUtils.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NFAllocInit/NFDateUtils.m b/NFAllocInit/NFDateUtils.m index d8671bf..d92dfcc 100644 --- a/NFAllocInit/NFDateUtils.m +++ b/NFAllocInit/NFDateUtils.m @@ -62,13 +62,13 @@ + (NSString *)isoStyleStringFromTimeInterval:(NSTimeInterval)timeInterval displa if (string.length > 0) { string = [string stringByAppendingString:@":"]; } - string = [string stringByAppendingFormat:@"%ld", minutes]; + string = [string stringByAppendingFormat:@"%02ld", minutes]; } if (timeUnitOptions & TimeUnitSeconds) { if (string.length > 0) { string = [string stringByAppendingString:@":"]; } - string = [string stringByAppendingFormat:@"%ld", seconds]; + string = [string stringByAppendingFormat:@"%02ld", seconds]; } return string; From c238b60af12487de5ad813110d2d81d61013c57f Mon Sep 17 00:00:00 2001 From: Ricardo Santos Date: Sun, 3 Feb 2019 11:54:33 +1030 Subject: [PATCH 09/10] Add device class for XR, XS Max and a hasNotch function --- NFAllocInit/NFDeviceUtils.h | 3 +++ NFAllocInit/NFDeviceUtils.m | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/NFAllocInit/NFDeviceUtils.h b/NFAllocInit/NFDeviceUtils.h index 77f6633..be100a6 100644 --- a/NFAllocInit/NFDeviceUtils.h +++ b/NFAllocInit/NFDeviceUtils.h @@ -18,6 +18,9 @@ + (BOOL)is4_7inch; + (BOOL)is5_5inch; + (BOOL)is5_8inch; ++ (BOOL)is6_1inch; ++ (BOOL)is6_5inch; ++ (BOOL)hasNotch; + (BOOL)isSmallPhone; + (BOOL)isSimulator; + (BOOL)isTwitterAvailable; diff --git a/NFAllocInit/NFDeviceUtils.m b/NFAllocInit/NFDeviceUtils.m index 30dbd73..24b9bf4 100644 --- a/NFAllocInit/NFDeviceUtils.m +++ b/NFAllocInit/NFDeviceUtils.m @@ -55,6 +55,20 @@ + (BOOL)is5_8inch { return SCREEN_MAX_LENGTH == 812.0; } ++ (BOOL)is6_1inch { + if ([self isPad]) return NO; + return SCREEN_MAX_LENGTH == 896.0 && [UIScreen mainScreen].scale == 2.0; +} + ++ (BOOL)is6_5inch { + if ([self isPad]) return NO; + return SCREEN_MAX_LENGTH == 896.0 && [UIScreen mainScreen].scale == 3.0; +} + ++ (BOOL)hasNotch { + return [self is5_8inch] || [self is6_1inch] || [self is6_5inch]; +} + + (BOOL)isSmallPhone { return ([self is3_5inch] || [self is4inch]); } From fd874dab9f09eef58741ca18607ef0e402603eaf Mon Sep 17 00:00:00 2001 From: Ricardo Santos Date: Wed, 20 Feb 2019 15:02:12 +1030 Subject: [PATCH 10/10] Update the podspec version --- NFAllocInit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NFAllocInit.podspec b/NFAllocInit.podspec index 5f3f692..3d5de9a 100644 --- a/NFAllocInit.podspec +++ b/NFAllocInit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "NFAllocInit" - s.version = "1.1.3" + s.version = "1.1.4" s.summary = "Helper classes and categories for iOS App development" s.description = <<-DESC The starting point for an iOS app - helper classes and the like.