Index: src/bridge/Makefile ================================================================== --- src/bridge/Makefile +++ src/bridge/Makefile @@ -7,15 +7,17 @@ FRAMEWORK = ${OBJFWBRIDGE_FRAMEWORK} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} SRCS = OFArray+NSObject.m \ + OFEnumerator+NSObject.m \ OFException+Swift.m \ OFDictionary+NSObject.m \ OFString+NSObject.m \ NSArray+OFObject.m \ NSDictionary+OFObject.m \ + NSEnumerator+OFObject.m \ NSString+OFObject.m INCLUDES := ${SRCS:.m=.h} \ NSBridging.h \ OFBridging.h \ ADDED src/bridge/NSEnumerator+OFObject.h Index: src/bridge/NSEnumerator+OFObject.h ================================================================== --- src/bridge/NSEnumerator+OFObject.h +++ src/bridge/NSEnumerator+OFObject.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import + +#import "NSBridging.h" + +OF_ASSUME_NONNULL_BEGIN + +@class OFEnumerator OF_GENERIC(ObjectType); + +#ifdef __cplusplus +extern "C" { +#endif +extern int _NSEnumerator_OFObject_reference; +#ifdef __cplusplus +} +#endif + +/*! + * @category NSEnumerator (OFObject) \ + * NSEnumerator+OFObject.h ObjFWBridge/NSEnumerator+OFObject.h + * + * @brief Support for bridging NSEnumerators to OFEnumerators. + */ +@interface NSEnumerator (OFObject) +@property (readonly, nonatomic) OFEnumerator *OFObject; +@end + +OF_ASSUME_NONNULL_END ADDED src/bridge/NSEnumerator+OFObject.m Index: src/bridge/NSEnumerator+OFObject.m ================================================================== --- src/bridge/NSEnumerator+OFObject.m +++ src/bridge/NSEnumerator+OFObject.m @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "NSEnumerator+OFObject.h" +#import "OFNSEnumerator.h" + +int _NSEnumerator_OFObject_reference; + +@implementation NSEnumerator (OFObject) +- (id)OFObject +{ + return [[[OFNSEnumerator alloc] + initWithNSEnumerator: self] autorelease]; +} +@end Index: src/bridge/NSOFDictionary.m ================================================================== --- src/bridge/NSOFDictionary.m +++ src/bridge/NSOFDictionary.m @@ -14,12 +14,12 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "NSOFDictionary.h" -#import "NSOFEnumerator.h" #import "OFDictionary.h" +#import "OFEnumerator+NSObject.h" #import "NSBridging.h" #import "OFBridging.h" #import "OFOutOfRangeException.h" @@ -65,9 +65,8 @@ return (NSUInteger)count; } - (NSEnumerator *)keyEnumerator { - return [[[NSOFEnumerator alloc] - initWithOFEnumerator: [_dictionary keyEnumerator]] autorelease]; + return [_dictionary keyEnumerator].NSObject; } @end ADDED src/bridge/OFEnumerator+NSObject.h Index: src/bridge/OFEnumerator+NSObject.h ================================================================== --- src/bridge/OFEnumerator+NSObject.h +++ src/bridge/OFEnumerator+NSObject.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#ifdef OF_BRIDGE_LOCAL_INCLUDES +# import "OFEnumerator.h" +#else +# if defined(__has_feature) && __has_feature(modules) +@import ObjFW; +# else +# import +# endif +#endif + +#import "OFBridging.h" + +OF_ASSUME_NONNULL_BEGIN + +#ifdef __cplusplus +extern "C" { +#endif +extern int _OFEnumerator_NSObject_reference; +#ifdef __cplusplus +} +#endif + +/*! + * @category OFEnumerator (NSObject) \ + * OFEnumerator+NSObject.h ObjFWBridge/OFEnumerator+NSObject.h + * @brief Support for bridging OFEnumerators to NSEnumerators. + */ +@interface OFEnumerator (NSObject) +@property (readonly, nonatomic) NSEnumerator *NSObject; +@end + +OF_ASSUME_NONNULL_END ADDED src/bridge/OFEnumerator+NSObject.m Index: src/bridge/OFEnumerator+NSObject.m ================================================================== --- src/bridge/OFEnumerator+NSObject.m +++ src/bridge/OFEnumerator+NSObject.m @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "NSOFEnumerator.h" + +#import "OFEnumerator+NSObject.h" + +int _OFEnumerator_NSObject_reference; + +@implementation OFEnumerator (NSObject) +- (id)NSObject +{ + return [[[NSOFEnumerator alloc] + initWithOFEnumerator: self] autorelease]; +} +@end Index: src/bridge/OFNSDictionary.m ================================================================== --- src/bridge/OFNSDictionary.m +++ src/bridge/OFNSDictionary.m @@ -16,11 +16,11 @@ */ #import #import "OFNSDictionary.h" -#import "OFNSEnumerator.h" +#import "NSEnumerator+OFObject.h" #import "NSBridging.h" #import "OFBridging.h" #import "OFInvalidArgumentException.h" @@ -70,9 +70,8 @@ return _dictionary.count; } - (OFEnumerator *)keyEnumerator { - return [[[OFNSEnumerator alloc] - initWithNSEnumerator: [_dictionary keyEnumerator]] autorelease]; + return [_dictionary keyEnumerator].OFObject; } @end