SHORT QUESTIONS

How will i print value in Optional Array without nil value

// // ViewController.swift // OptionalArrayDemo // // Created by Joynal Abedin on 23/2/23. // import UIKit class ViewController: UIViewController { let numberArray: [Int?] = [2, 4, nil, 6, nil, nil,...

J
Joynal Abedin
4
//
//  ViewController.swift
//  OptionalArrayDemo
//
//  Created by Joynal Abedin on 23/2/23.
//

import UIKit

class ViewController: UIViewController {
    
    let numberArray: [Int?] = [2, 4, nil, 6, nil, nil, 1]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // print number without nil value
        for case let element? in numberArray {
            print(element)
        }
        
        //print nill without number
        for case nil in numberArray {
            print(\"nil value\")
        }
    }
}
J

Written by Joynal Abedin

Passionate about technology, code, and sharing knowledge.

0 Comments

Leave a Comment