Just simply call with a student ref there contain UnsafePointer name.
let stu = student(id: 1, name: input?.cString(using: .utf8), percentage: 10.0)
passByStudent(stu)
Try this example:
MyC.c
#include <stdio.h>
void changeInput(int *output) {
*output = 5;
}
typedef struct student Student ;
void passByStudent(Student stu);
struct student {
int id;
const char *name;
float percentage;
};
void passByStudent(Student stu) {
stu.id = 5;
}
ViewController.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var output: CInt = 0
changeInput(&output)
print("output: \(output)")
let input: String? = "strudent name"
let stu = student(id: 1, name: input?.cString(using: .utf8), percentage: 10.0)
passByStudent(stu)
}
}
Follow this example step-by-step:
Create a Swift Project
Create MyC.c file and write code.

- Click on your project.
- Click the Build Setting Tab.
- Select all tab
- search with Objective-c Bridging Header
- Double click Here.
- After that left-click on MyC.c file, drag and drop inside popup layer.

You can define your function inside Practice-Bridging-Header.h
void changeInput(int *output);

- Write code inside your ViewController.
Code:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var output: CInt = 0
changeInput(&output)
print("output: \(output)")
let input: String? = "strudent name"
let stu = student(id: 1, name: input?.cString(using: .utf8), percentage: 10.0)
passByStudent(stu)
}
}