Skip to content

Instantly share code, notes, and snippets.

@jspahrsummers

jspahrsummers/iflet.m

Forked from cdzombak/iflet.m
Last active Aug 29, 2015
Embed
What would you like to do?
#import <Foundation/Foundation.h>
#define iflet(LHS, RHS) \
for (id obj_ = (RHS); obj_ != nil;) \
for (LHS = (obj_ ?: (RHS)); obj_ != nil; obj_ = nil)
int main(int argc, char *argv[]) {
@autoreleasepool {
NSString *x = nil;
NSString *y = @"y";
iflet(NSString *z, x) {
NSLog(@"x is non-nil: %@", z);
}
iflet(NSString *z, y) {
NSLog(@"y is non-nil: %@", z);
}
}
}
/* outputs:
Untitled[44105:2794964] y is non-nil: y
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment