为什么我不能在应用程序委托中执行此操作?

Why can't I do this in app delegate?

UIWindow *second = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
NSMutableArray *wArray = [NSMutableArray arrayWithArray:[UIApplication sharedApplication].windows];
[wArray addObject:second];
[[UIApplication sharedApplication] setValue:wArray forKey:@"windows"];

此代码在 KVC 之后崩溃。我只是想测试 UIApplication 的 windows 属性。

Application.hclass中你会发现大约window

@property(nullable, nonatomic,readonly) UIWindow *keyWindow;
@property(nonatomic,readonly) NSArray<__kindof UIWindow *>  *windows;

这清楚地表明 windows 是只读的。因此,您不能 set/override windows.

的任何值