-1

I'm trying to pass a function to a closure or another function, but there are overloads which prevent compilation due to ambiguity. I'm wondering if this can actually be done?

Here's a simple example of what I'm trying to achieve -

let closure: (UILabel, String, ((CGFloat) -> (UIFont))) -> () = { (label, text, createFont) in
    label.text = text
    label.font = createFont(20)
}

let systemFont = UIFont.systemFont  // won't compile - Ambiguous use of 'systemFont'
let boldSystemFont = UIFont.boldSystemFont // this is fine, no overloads

closure(myLabel, "Some text", systemFont)
closure(myOtherLabel, "More text", boldSystemFont)

Is there a way to specify which overload I want? No amount of searching on SO or Google has been able to answer this for me.

SomaMan
  • 4,127
  • 1
  • 34
  • 45
  • "Is there a way to specify which overload I want? No amount of searching on SO or Google has been able to answer this for me." Really? So what's this: https://stackoverflow.com/a/35658335/341994 – matt Sep 19 '18 at 18:35
  • That question specifically asks about #selector, so it never appeared in my search results – SomaMan Sep 19 '18 at 18:39
  • Possible duplicate of [How do I resolve "ambiguous use of" compile error with Swift #selector syntax?](https://stackoverflow.com/questions/35658334/how-do-i-resolve-ambiguous-use-of-compile-error-with-swift-selector-syntax) – Drenmi Sep 20 '18 at 06:43

1 Answers1

1

Perhaps you mean:

    let systemFont = UIFont.systemFont(ofSize:)
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Yup - this is the answer, thanks. Makes me feel a bit daft, pretty straight forward in the end... – SomaMan Sep 19 '18 at 18:40