Skip to content

Commit e968a53

Browse files
committed
🔨 Added a method to fetch all children of a particular wrapper
1 parent 91ea225 commit e968a53

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

LSFileWrapper.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ FOUNDATION_EXPORT const unsigned char LSFileWrapperVersionString[];
137137
*/
138138
- (nullable LSFileWrapper *)fileWrapperWithPath:(nonnull NSString *)path create:(BOOL)create isDirectory:(BOOL)isDir;
139139

140+
/**
141+
* @brief Finds all first-degree child wrappers of a directory wrapper found at supplied path in the current LSFileWrapper and its children traversing by path.
142+
*
143+
* @warning Should only be called on the LSFileWrapper of type Directory.
144+
*
145+
* @param path Relative path of directory wrapper, whose children we want to get as NSString.
146+
*
147+
* @return Array of stored child wrappers, each as LSFileWrapper.
148+
*/
149+
- (nonnull NSArray<LSFileWrapper*> *)fileWrappersInPath:(nonnull NSString *)path;
150+
140151
/**
141152
* @brief Adds a new child wrapper with the supplied name to the current LSFileWrapper. If a wrapper is already present with the same name, then the new wrapper will be saved under the returned named to prevent collisions.
142153
*

LSFileWrapper.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ - (LSFileWrapper *)fileWrapperWithPath:(NSString *)path
224224
return [self fileWrapperWithPath:path create:NO isDirectory:NO];
225225
}
226226

227+
- (NSArray<LSFileWrapper*> *)fileWrappersInPath:(NSString *)path
228+
{
229+
NSMutableArray<LSFileWrapper*> *array = [[NSMutableArray alloc] init];
230+
LSFileWrapper *dirFileWrapper = [self fileWrapperWithPath:path];
231+
if (dirFileWrapper) {
232+
[dirFileWrapper.fileWrappers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, LSFileWrapper * _Nonnull obj, BOOL * _Nonnull stop) {
233+
[array addObject:obj];
234+
}];
235+
}
236+
return [array copy];
237+
}
238+
227239
- (LSFileWrapper *)fileWrapperWithPath:(NSString *)path create:(BOOL)create isDirectory:(BOOL)isDir
228240
{
229241
NSString *dirpath = [path stringByDeletingLastPathComponent];

LSFileWrapper.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
3B1C07D222D893A900244E2D /* LSFileWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LSFileWrapper.h; sourceTree = "<group>"; };
2626
3B1C07D322D893A900244E2D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2727
3B6C6ABD2353C47D00E989C2 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
28+
3B73C1E325BDE2BB000E4B4E /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
29+
3B73C1E425BDE2BB000E4B4E /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
2830
/* End PBXFileReference section */
2931

3032
/* Begin PBXFrameworksBuildPhase section */
@@ -49,6 +51,8 @@
4951
isa = PBXGroup;
5052
children = (
5153
3B6C6ABD2353C47D00E989C2 /* Package.swift */,
54+
3B73C1E325BDE2BB000E4B4E /* README.md */,
55+
3B73C1E425BDE2BB000E4B4E /* LICENSE */,
5256
3B1C07D822D894BC00244E2D /* LSFileWrapper */,
5357
3B1C07BB22D8922900244E2D /* Products */,
5458
);

macOS/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSHumanReadableCopyright</key>
22-
<string>Copyright © 2013 Luke Scott. Copyright © 2019 Adam Kopeć. All rights reserved.</string>
22+
<string>Copyright © 2013 Luke Scott. Copyright © 2021 Adam Kopeć. All rights reserved.</string>
2323
</dict>
2424
</plist>

0 commit comments

Comments
 (0)