Skip to content

Instantly share code, notes, and snippets.

@niw
Created July 7, 2023 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niw/382216a31ebc9936799d8768381d1e50 to your computer and use it in GitHub Desktop.
Save niw/382216a31ebc9936799d8768381d1e50 to your computer and use it in GitHub Desktop.
A parser for the visual format string
@import AppKit;
@import Foundation;
#include <stdio.h>
int main(int argc, char *argv[]) {
@try {
if (argc < 2) {
printf("Usage: %s [visual format for a 'view']\n", argv[0]);
return 0;
}
NSString * const visualFormat = [[NSString alloc] initWithUTF8String:argv[1]];
NSView * const view = [[NSView alloc] init];
NSArray * const constraints =
[NSLayoutConstraint constraintsWithVisualFormat:visualFormat
options:0
metrics:nil
views:@{@"view": view}];
for (NSLayoutConstraint * const constraint in constraints) {
printf("%s\n", constraint.description.UTF8String);
}
} @catch(NSException *exception) {
printf("Error: %s\n", exception.reason.UTF8String);
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment