Created
June 18, 2018 14:02
-
-
Save jjrscott/26d23f4f2a0fe45701b0876aa3016423 to your computer and use it in GitHub Desktop.
An ObjC equivalent of Swift's `if let`
This file contains 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
// | |
// JJRSIfKind.h | |
// JJRSFoundation | |
// | |
// Copyright © 2018 John Scott ( https://jjrscott.com ) | |
// | |
// This file is MIT licensed. | |
// Usage: ifkind (existing variable, required class name) { ... } | |
#define ifkind(anExistingVariable, aClass) __ifkind(anExistingVariable, aClass, __ifkind_temp(__COUNTER__)) | |
#define __ifkind(anExistingVariable, aClass, tempVariable) \ | |
id tempVariable = [anExistingVariable isKindOfClass:[aClass class]]?anExistingVariable:nil; \ | |
for (aClass * const anExistingVariable = tempVariable,*__ifkind_test = tempVariable; tempVariable && __ifkind_test; __ifkind_test=nil) | |
#define __ifkind_temp_imp( aCount ) __ifkind_ ## aCount ## __ | |
#define __ifkind_temp( aCount ) __ifkind_temp_imp( aCount ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment