简体   繁体   中英

Mutate property in object array F#

I have an array of type UIView in F# initialized like this:

let mutable views = Array.init 100 (fun x -> new UIView())

I want to change the property named BackgroundColor in each view, so I have this:

views |> Array.iter (fun (x:UIView) -> (x.BackgroundColor <- UIColor.Blue))

But this isn't changing the property. What am I missing? This is Xamarin iOS F# btw.

Guess i asked too soon. The answer is not to annotate the type x in the anonymous function. so doing this:

views 
|> Array.iter (fun x -> x.BackgroundColor <- UIColor.Blue) 
|> this.View.AddSubViews

is done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM