Skip to content

Instantly share code, notes, and snippets.

@StephenHeaps
Last active August 5, 2018 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StephenHeaps/40ea93012600f7e9abad9bd9bdc9084b to your computer and use it in GitHub Desktop.
Save StephenHeaps/40ea93012600f7e9abad9bd9bdc9084b to your computer and use it in GitHub Desktop.
Quick fix for enumerateValues(forProperties: block:) returning value as type Any instead of Any? (as a Category on MPMediaItem)
//
// MPMediaItemEnumerateValuesNullabilityFix.h
// Shuffle
//
// Created by Stephen Heaps on 2018-02-13.
// Copyright © 2018 Stephen Heaps. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
@interface MPMediaItem (FixEnumerateValues)
// Fix for value being _Nonnull instead of _Nullable. Breaks Swift compatibility. (rdar://40779720)
- (void)fixed_enumerateValuesForProperties:(NSSet<NSString *> *_Nonnull)properties
using:(void (^_Nonnull)(NSString * _Nonnull property, _Nullable id value, BOOL * _Nonnull stop))block;
@end
//
// MPMediaItemEnumerateValuesNullabilityFix.m
// Shuffle
//
// Created by Stephen Heaps on 2018-02-13.
// Copyright © 2018 Stephen Heaps. All rights reserved.
//
#import "MPMediaItemEnumerateValuesNullabilityFix.h"
@implementation MPMediaItem (FixEnumerateValues)
- (void)fixed_enumerateValuesForProperties:(NSSet<NSString *> *)properties
using:(void (^)(NSString *property, _Nullable id value, BOOL *stop))block {
[self enumerateValuesForProperties:properties usingBlock:^(NSString * _Nonnull property, id _Nonnull value, BOOL * _Nonnull stop) {
id _Nullable valueNullable = value;
block(property, valueNullable, stop);
}];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment