String Structs

Looking through a file from the Facebook iOS SDK, I came across a reference to this:-

1
if (appBridgeType && [dictionary[FBAppBridgeTypesMetadata.tag] isEqualToString:FBAppBridgeTypesTags.png])

The bit that interested me in particular was the use of FBAppBridgeTypesMetadata.tag and FBAppBridgeTypesTags.png which seemed to be strings and constants. I've used string constants before, but have never seen this .xyz construction.

It turns out its a simple struct:-

1
2
3
4
5
6
7
static const struct {
    NSString *data;
    NSString *png;
} FBAppBridgeTypesTags = {
    .data = @"data",
    .png = @"png",
};

I do rather like the way this is so self-contained. Must endeavour to learn a bit more C!!

Comments

comments powered by Disqus
Copyright © 2013 - Brothers Bennett - Powered by Hexo
- Ported theme GreyShade -