Browse Source

vm: refactored common functions into category

osy 5 years ago
parent
commit
fb3eeda408

+ 6 - 1
Views/UIViewController+Extensions.h

@@ -18,8 +18,13 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
-@interface UIViewController (ShowAlert)
+@interface UIViewController (Extensions)
+
+- (void)onDelay:(float)delay action:(void (^)(void))block;
+- (BOOL)boolForSetting:(NSString *)key;
+- (NSInteger)integerForSetting:(NSString *)key;
 - (void)showAlert:(NSString *)msg actions:(nullable NSArray<UIAlertAction *> *)actions completion:(nullable void (^)(UIAlertAction *action))completion;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 13 - 1
Views/UIViewController+Extensions.m

@@ -16,7 +16,19 @@
 
 #import "UIViewController+Extensions.h"
 
-@implementation UIViewController (ShowAlert)
+@implementation UIViewController (Extensions)
+
+- (void)onDelay:(float)delay action:(void (^)(void))block {
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC*0.1), dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), block);
+}
+
+- (BOOL)boolForSetting:(NSString *)key {
+    return [[NSUserDefaults standardUserDefaults] boolForKey:key];
+}
+
+- (NSInteger)integerForSetting:(NSString *)key {
+    return [[NSUserDefaults standardUserDefaults] integerForKey:key];
+}
 
 - (void)showAlert:(NSString *)msg actions:(nullable NSArray<UIAlertAction *> *)actions completion:(nullable void (^)(UIAlertAction *action))completion {
     UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:msg preferredStyle:UIAlertControllerStyleAlert];

+ 1 - 0
Views/VMDisplayMetalViewController+Keyboard.m

@@ -14,6 +14,7 @@
 // limitations under the License.
 //
 
+#import "UIViewController+Extensions.h"
 #import "VMDisplayMetalViewController+Keyboard.h"
 #import "UTMVirtualMachine.h"
 #import "VMKeyboardView.h"

+ 1 - 0
Views/VMDisplayMetalViewController+Touch.m

@@ -14,6 +14,7 @@
 // limitations under the License.
 //
 
+#import "UIViewController+Extensions.h"
 #import "VMDisplayMetalViewController.h"
 #import "VMDisplayMetalViewController+Touch.h"
 #import "VMCursor.h"

+ 0 - 3
Views/VMDisplayMetalViewController.h

@@ -77,9 +77,6 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic, readonly) BOOL autosaveLowMemory;
 
 - (void)sendExtendedKey:(SendKeyType)type code:(int)code;
-- (void)onDelay:(float)delay action:(void (^)(void))block;
-- (BOOL)boolForSetting:(NSString *)key;
-- (NSInteger)integerForSetting:(NSString *)key;
 
 - (IBAction)changeDisplayZoom:(UIButton *)sender;
 - (IBAction)pauseResumePressed:(UIButton *)sender;

+ 0 - 12
Views/VMDisplayMetalViewController.m

@@ -236,18 +236,6 @@
     }
 }
 
-- (void)onDelay:(float)delay action:(void (^)(void))block {
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC*0.1), dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), block);
-}
-
-- (BOOL)boolForSetting:(NSString *)key {
-    return [[NSUserDefaults standardUserDefaults] boolForKey:key];
-}
-
-- (NSInteger)integerForSetting:(NSString *)key {
-    return [[NSUserDefaults standardUserDefaults] integerForKey:key];
-}
-
 #pragma mark - Toolbar actions
 
 - (UIStatusBarStyle)preferredStatusBarStyle {