swift - Calling the built-in function with the same name as a custom function -


i have following code round value nearest number:

func round(_ value: double, tonearest nearest: double) -> double {     let roundedvalue = round(value / nearest) * nearest     return roundedvalue } 

however, following complaint because use same name method builtin one:

missing argument parameter 'tonearest' in call 

is there way around this? i.e. builtin round(value / nearest)?

thanks.

as shown in following answer:

most darwin/c rounding methods readily available native swift methods, types conforming floatingpoint (e.g. double , float). means if set on implementing own rounding method using same logic in question, can use rounded() method of floatingpoint, make use of .tonearestorawayfromzero rounding rule, (as described in linked answer) equivalent darwin/c round(...) method.

applied modify custom round(_:tonearest:) function:

func round(_ value: double, tonearest nearest: double) -> double {     return (value / nearest).rounded() * nearest } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -