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.
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
+
+
+
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
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
diff --git a/NFAllocInit/NFDateUtils.h b/NFAllocInit/NFDateUtils.h
index 40131c7..1e222a3 100644
--- a/NFAllocInit/NFDateUtils.h
+++ b/NFAllocInit/NFDateUtils.h
@@ -8,14 +8,21 @@
#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
@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 f735d21..d92dfcc 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;
@@ -43,12 +42,38 @@ + (NSString *)stringFromTimeInterval:(NSTimeInterval)timeInterval
return string;
}
-
+ (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:@"%02ld", minutes];
+ }
+ if (timeUnitOptions & TimeUnitSeconds) {
+ if (string.length > 0) {
+ string = [string stringByAppendingString:@":"];
+ }
+ string = [string stringByAppendingFormat:@"%02ld", seconds];
+ }
+
+ return string;
+}
+
+ (NSString *)stringFromDate:(NSDate *)date withStyle:(NSDateFormatterStyle)style
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
@@ -85,6 +110,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;
}
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]);
}