-
-
Save niw/382216a31ebc9936799d8768381d1e50 to your computer and use it in GitHub Desktop.
A parser for the visual format string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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