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, 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")
        }
    }
}

25 thoughts on “How will i print value in Optional Array without nil value

Leave a Reply

Your email address will not be published. Required fields are marked *