//学生结构体 typedef struct student { char name[20]; //姓名 char sex; //性别 int age; //年龄 }Student; int main(int argc, const char * argv[]) { Student stu={"xiaorui",‘f‘,24}; NSValue *structObject={0}; //将结构体转换为对象 structObject=[NSValue value:&stu withObjCType:@encode(Student)]; NSLog(@"%@",structObject); //将对象转换为结构体 Student stu2={0}; [structObject getValue:&stu2]; NSLog(@"%s %c %d",stu2.name,stu2.sex,stu2.age); return 0; }
时间: 2024-12-10 21:28:04