I want to create an array in Swift that is of type UIImageView but should initially have some empty fields (nil) that act as placeholders. Is that possible? It was easy to create in Objective-C, like:
[self.pageViews addObject:[NSNull null]]
In Swift I define the array like this:
var pageViews:Array<UIImageView> = [];
override func viewDidLoad()
{
super.viewDidLoad();
for i in 0 ..< 5
{
pageViews.append(nil);
}
}
Of course that doesn't work. If I define the array with
var pageViews:Array<UIImageView!> = [];
I wont get a compile-time error but the app throws a fatal error:
fatal error: attempt to bridge an implicitly unwrapped optional containing nil
Is there any good workaround for this problem?
Array<UIImageView!>, what is the exclamation mark doing here exactly?UIImageView!is an implicitly-unwrapped optional ofUIImageView