Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ricsantos committed Feb 20, 2019
2 parents 2cbde4f + fd874da commit 0a44302
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 6 deletions.
2 changes: 1 addition & 1 deletion NFAllocInit.podspec
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
2 changes: 2 additions & 0 deletions NFAllocInit/Categories/NSString+NFAllocInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
- (NSString *)trim;
- (NSArray<NSString *> *)matchesForRegex:(NSString *)regex options:(NSRegularExpressionOptions)options;

+ (NSString *)randomAlphanumericStringWithLength:(NSInteger)length;

@end

NS_ASSUME_NONNULL_END
13 changes: 13 additions & 0 deletions NFAllocInit/Categories/NSString+NFAllocInit.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,17 @@ - (NSString *)trim {
return [NSArray<NSString *> 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
1 change: 1 addition & 0 deletions NFAllocInit/Categories/UIView+NFAllocInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@

- (void)printAllSubviews;
- (nullable UIViewController *)findViewController;
- (void)sizeToFitCeiling;

@end
4 changes: 4 additions & 0 deletions NFAllocInit/Categories/UIView+NFAllocInit.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion NFAllocInit/NFDateUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@

#import <Foundation/Foundation.h>

#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;
Expand Down
37 changes: 33 additions & 4 deletions NFAllocInit/NFDateUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions NFAllocInit/NFDeviceUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions NFAllocInit/NFDeviceUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down

0 comments on commit 0a44302

Please # to comment.