Skip to content

Commit 0a44302

Browse files
committed
Merge branch 'develop'
2 parents 2cbde4f + fd874da commit 0a44302

File tree

10 files changed

+87
-6
lines changed

10 files changed

+87
-6
lines changed

NFAllocInit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "NFAllocInit"
3-
s.version = "1.1.3"
3+
s.version = "1.1.4"
44
s.summary = "Helper classes and categories for iOS App development"
55
s.description = <<-DESC
66
The starting point for an iOS app - helper classes and the like.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

NFAllocInit/Categories/NSString+NFAllocInit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
1818
- (NSString *)trim;
1919
- (NSArray<NSString *> *)matchesForRegex:(NSString *)regex options:(NSRegularExpressionOptions)options;
2020

21+
+ (NSString *)randomAlphanumericStringWithLength:(NSInteger)length;
22+
2123
@end
2224

2325
NS_ASSUME_NONNULL_END

NFAllocInit/Categories/NSString+NFAllocInit.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,17 @@ - (NSString *)trim {
5959
return [NSArray<NSString *> array];
6060
}
6161

62+
+ (NSString *)randomAlphanumericStringWithLength:(NSInteger)length {
63+
// https://stackoverflow.com/a/2633948/883413
64+
65+
NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
66+
NSMutableString *randomString = [NSMutableString stringWithCapacity:length];
67+
68+
for (int i = 0; i < length; i++) {
69+
[randomString appendFormat:@"%C", [letters characterAtIndex:arc4random() % [letters length]]];
70+
}
71+
72+
return randomString;
73+
}
74+
6275
@end

NFAllocInit/Categories/UIView+NFAllocInit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111

1212
- (void)printAllSubviews;
1313
- (nullable UIViewController *)findViewController;
14+
- (void)sizeToFitCeiling;
1415

1516
@end

NFAllocInit/Categories/UIView+NFAllocInit.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,9 @@ - (UIViewController*)findViewController
4141
return nil;
4242
}
4343

44+
- (void)sizeToFitCeiling {
45+
CGSize size = [self sizeThatFits:self.bounds.size];
46+
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, ceilf(size.width), ceilf(size.height));
47+
}
4448

4549
@end

NFAllocInit/NFDateUtils.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@
88

99
#import <Foundation/Foundation.h>
1010

11-
#define NFDateFormatISO_8601 @"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"
11+
#define NFDateFormatISO_8601 @"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'"
1212
#define NFDateFormatStandard @"yyyy-MM-dd hh:mm:ss a"
1313

1414
NS_ASSUME_NONNULL_BEGIN
1515

1616
@interface NFDateUtils : NSObject
1717

18+
typedef NS_OPTIONS(NSUInteger, TimeUnitOptions) {
19+
TimeUnitSeconds = 1 << 0,
20+
TimeUnitMinutes = 1 << 1,
21+
TimeUnitHours = 1 << 2,
22+
};
23+
1824
+ (NSString *)stringFromTimeInterval:(NSTimeInterval)timeInterval;
25+
+ (NSString *)isoStyleStringFromTimeInterval:(NSTimeInterval)timeInterval displayingTimeUnitOptions:(TimeUnitOptions)timeUnitOptions;
1926

2027
+ (NSString *)stringFromDate:(NSDate *)date;
2128
+ (NSString *)stringFromDate:(NSDate *)date withStyle:(NSDateFormatterStyle)style;

NFAllocInit/NFDateUtils.m

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ + (NSString *)stringForValue:(NSUInteger)value withNonPluralUnit:(NSString *)uni
2020

2121
+ (NSString *)stringFromTimeInterval:(NSTimeInterval)timeInterval
2222
{
23-
NSUInteger time = (NSUInteger)timeInterval;
24-
NSUInteger seconds = time % 60;
25-
NSUInteger minutes = time / 60;
23+
NSUInteger seconds = (NSUInteger)timeInterval;
24+
NSUInteger minutes = seconds / 60;
2625
NSUInteger hours = minutes / 60;
2726
NSUInteger days = hours / 24;
2827
NSUInteger weeks = days / 7;
@@ -43,12 +42,38 @@ + (NSString *)stringFromTimeInterval:(NSTimeInterval)timeInterval
4342
return string;
4443
}
4544

46-
4745
+ (NSString *)stringFromDate:(NSDate *)date
4846
{
4947
return [NFDateUtils stringFromDate:date withFormat:NFDateFormatISO_8601];
5048
}
5149

50+
+ (NSString *)isoStyleStringFromTimeInterval:(NSTimeInterval)timeInterval displayingTimeUnitOptions:(TimeUnitOptions)timeUnitOptions
51+
{
52+
NSUInteger time = (NSUInteger)timeInterval;
53+
NSUInteger hours = time / 3600;
54+
NSUInteger minutes = (time / 60) % 60;
55+
NSUInteger seconds = time % 60;
56+
57+
NSString *string = @"";
58+
if (timeUnitOptions & TimeUnitHours) {
59+
string = [string stringByAppendingFormat:@"%lu", hours];
60+
}
61+
if (timeUnitOptions & TimeUnitMinutes) {
62+
if (string.length > 0) {
63+
string = [string stringByAppendingString:@":"];
64+
}
65+
string = [string stringByAppendingFormat:@"%02ld", minutes];
66+
}
67+
if (timeUnitOptions & TimeUnitSeconds) {
68+
if (string.length > 0) {
69+
string = [string stringByAppendingString:@":"];
70+
}
71+
string = [string stringByAppendingFormat:@"%02ld", seconds];
72+
}
73+
74+
return string;
75+
}
76+
5277
+ (NSString *)stringFromDate:(NSDate *)date withStyle:(NSDateFormatterStyle)style
5378
{
5479
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
@@ -85,6 +110,10 @@ + (NSDate *)dateFromString:(NSString *)string withFormat:(NSString *)dateFormat
85110
{
86111
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
87112
formatter.dateFormat = dateFormat;
113+
114+
NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
115+
[formatter setTimeZone:timeZone];
116+
88117
NSDate *date = [formatter dateFromString:string];
89118
return date;
90119
}

NFAllocInit/NFDeviceUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
+ (BOOL)is4_7inch;
1919
+ (BOOL)is5_5inch;
2020
+ (BOOL)is5_8inch;
21+
+ (BOOL)is6_1inch;
22+
+ (BOOL)is6_5inch;
23+
+ (BOOL)hasNotch;
2124
+ (BOOL)isSmallPhone;
2225
+ (BOOL)isSimulator;
2326
+ (BOOL)isTwitterAvailable;

NFAllocInit/NFDeviceUtils.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ + (BOOL)is5_8inch {
5555
return SCREEN_MAX_LENGTH == 812.0;
5656
}
5757

58+
+ (BOOL)is6_1inch {
59+
if ([self isPad]) return NO;
60+
return SCREEN_MAX_LENGTH == 896.0 && [UIScreen mainScreen].scale == 2.0;
61+
}
62+
63+
+ (BOOL)is6_5inch {
64+
if ([self isPad]) return NO;
65+
return SCREEN_MAX_LENGTH == 896.0 && [UIScreen mainScreen].scale == 3.0;
66+
}
67+
68+
+ (BOOL)hasNotch {
69+
return [self is5_8inch] || [self is6_1inch] || [self is6_5inch];
70+
}
71+
5872
+ (BOOL)isSmallPhone {
5973
return ([self is3_5inch] || [self is4inch]);
6074
}

0 commit comments

Comments
 (0)