Skip to content
Snippets Groups Projects
Commit 3d98ef99 authored by Romain Bertozzi's avatar Romain Bertozzi Committed by Silbino Gonçalves Matado
Browse files

utils: add utility method for vectors and arrays


This patch adds a new utility method to convert C++ data containers to
Objective-C ones.
Here, std::vector of std::map containers are translated to NSArray of
NSDictionary.

Issue: #1391
Change-Id: I61f7a57d2801949eac5685ffb0d734f26eeab87c
Reviewed-by: default avatarSilbino Gonçalves Matado <silbino.gmatado@savoirfairelinux.com>
parent 1caaa4be
No related branches found
No related tags found
No related merge requests found
...@@ -31,5 +31,6 @@ ...@@ -31,5 +31,6 @@
+ (NSMutableDictionary*)mapToDictionnary: + (NSMutableDictionary*)mapToDictionnary:
(const std::map<std::string, std::string>&)map; (const std::map<std::string, std::string>&)map;
+ (std::map<std::string, std::string>)dictionnaryToMap:(NSDictionary*)dict; + (std::map<std::string, std::string>)dictionnaryToMap:(NSDictionary*)dict;
+ (NSArray*)vectorOfMapsToArray:(const std::vector<std::map<std::string, std::string>>&)vectorOfMaps;
@end @end
...@@ -56,4 +56,17 @@ ...@@ -56,4 +56,17 @@
return resMap; return resMap;
} }
+ (NSArray*)vectorOfMapsToArray:
(const std::vector<std::map<std::string, std::string>>&)vectorOfMaps {
NSMutableArray* array = [[NSMutableArray alloc] initWithCapacity:vectorOfMaps.size()];
std::for_each(
vectorOfMaps.begin(), vectorOfMaps.end(), ^(std::map<std::string, std::string> map) {
NSDictionary *dictionary = [Utils mapToDictionnary:map];
[array addObject:dictionary];
});
return [NSArray arrayWithArray:array];
}
@end @end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment