BluGeni BluGeni - 3 months ago 26
Swift Question

Cannot invoke initializer for type 'CGFloat' with an argument list of type '(CGFloat)'

I am not quite understanding this compile error because I don't get this error and can compile and run on a real device, but if I try to build and run on a simulator I get this error.


Cannot invoke initializer for type 'CGFloat' with an argument list of type '(CGFloat)'


Here is the line of code that causes the error:

loadingNotification.yOffset = CGFloat(CGRectGetMinY(self.tableView.bounds))


Furthermore if I change it to

loadingNotification.yOffset = Float(CGRectGetMinY(self.tableView.bounds))


It works on the simulators but not on the real device I get


'Cannot assign value of type 'Float' to type 'CGFloat'


Any ideas to as why this is behaving like this?

Answer

You can write just this:

#if (arch(i386) || arch(x86_64)) && os(iOS)
    loadingNotification.yOffset = Float(CGRectGetMinY(self.tableView.bounds))
#else
    loadingNotification.yOffset = CGRectGetMinY(self.tableView.bounds)
#endif

Anyway try to understand why you have CGFloat in device and Float in sim