-
-
Save dreampiggy/d0ef34138dc962b16736c48b0980f731 to your computer and use it in GitHub Desktop.
foreach in Objective-C. Credits go to https://twitter.com/Tricertops, see https://mjtsai.com/blog/2017/05/08/foreach-using-objective-c-generics/ - ships in https://pdfviewer.io
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
// | |
// PSPDFFastEnumeration.h | |
// PSPDFFoundation | |
// | |
// PSPDFKit is the leading cross-platform solution for integrating PDFs into your apps: https://pspdfkit.com. | |
// Try it today using our free PDF Viewer app: https://pdfviewer.io/ | |
// | |
// This file is MIT licensed. | |
@protocol PSPDFFastEnumeration <NSFastEnumeration> | |
- (id)pspdf_enumeratedType; | |
@end | |
// Usage: foreach (s, strings) { ... } | |
#define foreach(element, collection) for (typeof((collection).pspdf_enumeratedType) element in (collection)) | |
@interface NSArray <ElementType> (PSPDFFastEnumeration) | |
<PSPDFFastEnumeration> | |
- (ElementType)pspdf_enumeratedType; | |
@end | |
@interface NSSet <ElementType> (PSPDFFastEnumeration) | |
<PSPDFFastEnumeration> | |
- (ElementType)pspdf_enumeratedType; | |
@end | |
@interface NSDictionary <KeyType, ValueType> (PSPDFFastEnumeration) | |
<PSPDFFastEnumeration> | |
- (KeyType)pspdf_enumeratedType; | |
@end | |
@interface NSOrderedSet <ElementType> (PSPDFFastEnumeration) | |
<PSPDFFastEnumeration> | |
- (ElementType)pspdf_enumeratedType; | |
@end | |
@interface NSPointerArray (PSPDFFastEnumeration) <PSPDFFastEnumeration> | |
- (void *)pspdf_enumeratedType; | |
@end | |
@interface NSHashTable <ElementType> (PSPDFFastEnumeration) | |
<PSPDFFastEnumeration> | |
- (ElementType)pspdf_enumeratedType; | |
@end | |
@interface NSMapTable <KeyType, ValueType> (PSPDFFastEnumeration) | |
<PSPDFFastEnumeration> | |
- (KeyType)pspdf_enumeratedType; | |
@end | |
@interface NSEnumerator <ElementType> (PSPDFFastEnumeration) | |
<PSPDFFastEnumeration> | |
- (ElementType)pspdf_enumeratedType; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment