Anyway easy way to find Swift API signature from Obj-C version?

This post refers to String method stringByPaddingToLength:withString:startingAtIndex:, I couldn't figure out how to call this with Swift syntax. For things like this, is there any simple way to get the Swift version of the method signature?

Usually you can select the language from the drop down, but if it’s not supported then I’m not sure if there’s a way other than searching for it manually. For the API you mentioned above, I believe the Swift equivalent is Apple Developer Documentation

1 Like

One trick I use is to do the wrong thing and then let the compiler suggest a fix-it. For example, if you write this in Xcode:

let s: NSString = ""
s.stringByPaddingToLength(_: 0, withString: "", startingAtIndex: 0)

you’ll get this error:

…/main.swift:14:7: error: 'stringByPaddingToLength(_:withString:startingAtIndex:)' has been renamed to 'padding(toLength:withPad:startingAt:)'
    s.stringByPaddingToLength(_: 0, withString: "", startingAtIndex: 0)
      ^~~~~~~~~~~~~~~~~~~~~~~       ~~~~~~~~~~      ~~~~~~~~~~~~~~~
      padding                    toLength:  withPad startingAt

and away you go!

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple