Files
comaps/iphone/CoreApi/CoreApi/Common/MWMCommon.h
Yannik Bloscheck 78b54acad4 [ios] Switching to iOS 15 as the minimum
Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
2025-06-25 13:31:07 +02:00

62 lines
1.7 KiB
Objective-C

#import <UIKit/UIKit.h>
#import "MWMTypes.h"
NS_ASSUME_NONNULL_BEGIN
static inline BOOL firstVersionIsLessThanSecond(NSString * first, NSString * second)
{
NSArray<NSString *> * f = [first componentsSeparatedByString:@"."];
NSArray<NSString *> * s = [second componentsSeparatedByString:@"."];
NSUInteger iter = 0;
while (f.count > iter && s.count > iter)
{
NSInteger fiv = f[iter].integerValue;
NSInteger siv = s[iter].integerValue;
if (fiv == siv)
iter++;
else
return fiv < siv;
}
return f.count < s.count;
}
static inline BOOL isIOSVersionLessThanString(NSString * version)
{
return firstVersionIsLessThanSecond(UIDevice.currentDevice.systemVersion, version);
}
static inline BOOL isIOSVersionLessThan(NSUInteger version)
{
return isIOSVersionLessThanString([NSString stringWithFormat:@"%@", @(version)]);
}
static inline BOOL isInterfaceRightToLeft(void) NS_EXTENSION_UNAVAILABLE_IOS("Not available in extensions")
{
return UIApplication.sharedApplication.userInterfaceLayoutDirection ==
UIUserInterfaceLayoutDirectionRightToLeft;
}
static inline NSString * formattedSize(uint64_t size)
{
return [NSByteCountFormatter stringFromByteCount:size
countStyle:NSByteCountFormatterCountStyleFile];
}
// Use only for screen dimensions CGFloat comparison
static inline BOOL equalScreenDimensions(CGFloat left, CGFloat right)
{
return fabs(left - right) < 0.5;
}
static inline void performOnce(MWMVoidBlock block, NSString *key) {
BOOL performed = [[NSUserDefaults standardUserDefaults] boolForKey:key];
if (!performed) {
block();
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:key];
}
}
NS_ASSUME_NONNULL_END