Find maximum number in an NSMutablearray iOS swift

 Problem:

I had Nsmutablearray with multiple values in nsnumber format.I want to get the maximum number in that array.How can i get that?

Solution: 

            var maxHeight = myArray.map { CGFloat($0 asNSNumber) }.max() ?? 40


Here i had myArray is my mutable array with dynamic type.But it had Nsnumber array.So i added as conditional.

maxHeight is float value so i converted nsnumber to cgfloat like

CGFloat($0 as! NSNumber

Also assigned to  maxheight variable.But it shows error that to apply conditional.But i had added that default value as 40.So it will never throw exception

max() function for fetching max value in that array...

Comments

Popular posts from this blog

How to blink a button iOS swift?

Convert NsNumber, NSDate to String in iOS Swift

Parse the value from string value iOS swift