objective-c - A question encountered in OC learning
怪我咯
怪我咯 2017-05-02 09:32:30
0
0
719

The processes in the operating system are not generated for no reason. They have their own parent processes, and each process is started by its own parent process. Now given the process parent-child relationship description table, use (│ ├ └ ─ ) characters to visually output this parent-child relationship.
Class Process describes process information, as follows:

@interface Process : NSObject
@property (nonatomic) NSString *name;   // 进程名
@property (nonatomic) NSArray<Process *> *children; // 子进程
@end
@implementation Process
-(instancetype)initWithName:(NSString*)name children:(NSArray<Process *> *)children {
  if (self = [super init]) {
    _name = name;
    _children = children;
  }
  return self;
}
- (instancetype)initFromDumpString:(NSString*)dump {
   // TODO
}
- (NSString*)dump {
    // TODO
}
@end

1) Your goal is to populate this method called dump, which returns a string that outputs the parent-child relationship in character form. You can refer to the following example.
【Example】

int main() {
    Process* xcode = [[Process alloc] initWithName:@"Xcode"
                                          children:@[[[Process alloc] initWithName:@"Simulator" children:nil],
                                                     [[Process alloc] initWithName:@"Debugger" children:nil]]];
    Process* finder = [[Process alloc] initWithName:@"Finder" children:nil];
    Process* qq = [[Process alloc] initWithName:@"QQ" children:nil];
    Process* launcher = [[Process alloc] initWithName:@"Launcher" children:@[xcode, finder, qq]];
     
    NSLog(@"%@", [launcher dump]);
    return 0;
}
/* 输出
Launcher
├─ Xcode
│  ├─ Simulator
│  └─ Debugger
├─ Finder
└─ QQ
*/ 

2) After completing step 1, you need to fill in the method named initFromDumpString:. This method is the reverse operation of step 1. It parses a character-based parent-child relationship string and returns an initialized Person object.

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template