Sample code for 30+ languages & platforms
Swift

Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem

See more OpenSSL Examples

How to output the public part of a private key: Demonstrates how to duplicate this OpenSSL command:
openssl pkey -in private.pem -pubout -out pubkey.pem

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let pkey = CkoPrivateKey()!

    // Load the private key from an PEM file:
    success = pkey.loadPemFile(path: "private.pem")
    if success == false {
        print("\(pkey.lastErrorText!)")
        return
    }

    let pubKey = CkoPublicKey()!
    pkey.toPublicKey(pubKey: pubKey)

    success = pubKey.savePemFile(preferPkcs1: false, path: "pubKey.pem")
    if success != true {
        print("\(pubKey.lastErrorText!)")
        pubKey = nil
        return
    }

    print("Success.")

}