ObjFW
Loading...
Searching...
No Matches
OFMutableDictionary.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#import "OFDictionary.h"
21
22OF_ASSUME_NONNULL_BEGIN
23
26#ifdef OF_HAVE_BLOCKS
34typedef id _Nonnull (^OFDictionaryReplaceBlock)(id key, id object);
35#endif
36
46@interface OFMutableDictionary OF_GENERIC(KeyType, ObjectType):
47 OFDictionary OF_GENERIC(KeyType, ObjectType)
48#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
49# define KeyType id
50# define ObjectType id
51#endif
59+ (instancetype)dictionaryWithCapacity: (size_t)capacity;
60
66- (instancetype)init OF_DESIGNATED_INITIALIZER;
67
75- (instancetype)initWithCapacity: (size_t)capacity OF_DESIGNATED_INITIALIZER;
76
85- (void)setObject: (ObjectType)object forKey: (KeyType)key;
86
98- (void)setObject: (nullable ObjectType)object forKeyedSubscript: (KeyType)key;
99
105- (void)removeObjectForKey: (KeyType)key;
106
110- (void)removeAllObjects;
111
117- (void)addEntriesFromDictionary:
118 (OFDictionary OF_GENERIC(KeyType, ObjectType) *)dictionary;
119
120#ifdef OF_HAVE_BLOCKS
126- (void)replaceObjectsUsingBlock: (OFDictionaryReplaceBlock)block;
127#endif
128
132- (void)makeImmutable;
133#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
134# undef KeyType
135# undef ObjectType
136#endif
137@end
138
139OF_ASSUME_NONNULL_END
id(^ OFDictionaryReplaceBlock)(id key, id object)
A block for replacing objects in an OFMutableDictionary.
Definition OFMutableDictionary.h:34
An abstract class for storing objects in a dictionary.
Definition OFDictionary.h:84
An abstract class for storing and changing objects in a dictionary.
Definition OFMutableDictionary.h:48
void removeAllObjects()
Removes all objects.
Definition OFMutableDictionary.m:161
void makeImmutable()
Converts the mutable dictionary to an immutable dictionary.
Definition OFMutableDictionary.m:204
instancetype init()
Initializes an already allocated OFMutableDictionary to be empty.
Definition OFMutableDictionary.m:117