Skip to content

Instantly share code, notes, and snippets.

@username0x0a
Last active November 22, 2020 18:12
Show Gist options
  • Save username0x0a/71d8677d14c9c2970fbc4033d1623ac1 to your computer and use it in GitHub Desktop.
Save username0x0a/71d8677d14c9c2970fbc4033d1623ac1 to your computer and use it in GitHub Desktop.
Very useful macro to get around some mutable/immutable assignment issues for basic Foundation types.
#import <Foundation/Foundation.h>
@interface NSString (FoundationMutabilityType)
- (NSString *)copy;
- (NSMutableString *)mutableCopy;
@end
@interface NSDictionary<KeyType, ObjectType> (FoundationMutabilityType)
- (NSDictionary<KeyType, ObjectType> *)copy;
- (NSMutableDictionary<KeyType, ObjectType> *)mutableCopy;
@end
@interface NSArray<ObjectType> (FoundationMutabilityType)
- (NSArray<ObjectType> *)copy;
- (NSMutableArray<ObjectType> *)mutableCopy;
@end
@interface NSSet<ObjectType> (FoundationMutabilityType)
- (NSSet<ObjectType> *)copy;
- (NSMutableSet<ObjectType> *)mutableCopy;
@end
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincomplete-implementation"
@implementation NSString (FoundationMutabilityType) @end
@implementation NSArray (FoundationMutabilityType) @end
@implementation NSDictionary (FoundationMutabilityType) @end
@implementation NSSet (FoundationMutabilityType) @end
#pragma clang diagnostic pop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment