Skip to content

Instantly share code, notes, and snippets.

@leptos-null
Last active August 31, 2019 22:43
Show Gist options
  • Save leptos-null/e8252155bb0576db74d81a37ad1d2493 to your computer and use it in GitHub Desktop.
Save leptos-null/e8252155bb0576db74d81a37ad1d2493 to your computer and use it in GitHub Desktop.
Recreating the UIStatusBarItemType enum
//
// statusbartypes
//
// Created by Leptos on 3/19/19.
// Copyright © 2019 Leptos. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef int UIStatusBarItemType;
API_AVAILABLE(ios(4.0))
@interface UIStatusBarItem : NSObject
@property (nonatomic, readonly) Class viewClass API_AVAILABLE(ios(6.0));
@property (nonatomic, readonly) NSString *indicatorName API_AVAILABLE(ios(6.0));
+ (BOOL)typeIsValid:(UIStatusBarItemType)type;
+ (instancetype)itemWithType:(UIStatusBarItemType)type idiom:(UIUserInterfaceIdiom)idiom API_AVAILABLE(ios(7.0));
@end
int main() {
// in newer SDKs, UIStatusBarItem (and other private UIKit symbols) are missing from the UIKit tbd
Class const UIStatusBarItemClass = NSClassFromString(@"UIStatusBarItem");
UIUserInterfaceIdiom const idiom = UIDevice.currentDevice.userInterfaceIdiom;
/* the name of viewClass typically conforms to the name scheme "UIStatusBar\(Identifier)ItemView" */
NSString *const classPrefix = @"UIStatusBar", *const classSuffix = @"ItemView";
NSUInteger const totalTrimLength = classSuffix.length + classPrefix.length;
// print device info
printf("/* %s %s */\n",
UIDevice.currentDevice.systemName.UTF8String,
NSProcessInfo.processInfo.operatingSystemVersionString.UTF8String);
puts("typedef enum {");
for (UIStatusBarItemType type = 0; [UIStatusBarItemClass typeIsValid:type]; type++) {
UIStatusBarItem *item = [UIStatusBarItemClass itemWithType:type idiom:idiom];
Class itemClass = item.viewClass;
NSString *indicatorName = item.indicatorName;
if (itemClass == nil) {
printf(" /* %d skipped */\n", type);
continue;
}
NSString *targetName = NSStringFromClass(itemClass);
if (![targetName hasPrefix:classPrefix]) {
NSLog(@"Warning: %d does not have expected prefix (%@)", type, targetName);
}
if (![targetName hasSuffix:classSuffix]) {
NSLog(@"Warning: %d does not have expected suffix (%@)", type, targetName);
}
targetName = [targetName substringWithRange:NSMakeRange(classPrefix.length, targetName.length - totalTrimLength)];
if (indicatorName) {
targetName = [targetName stringByAppendingString:indicatorName];
}
printf(" UIStatusBarItemType%s = %d,\n", targetName.UTF8String, type);
}
puts("} UIStatusBarItemType;");
}
@leptos-null
Copy link
Author

Doesn't look like an ABI stable enum.

@kirb should this be removed from theos/headers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment