What's the easiest way to create an array of structs?

前端 未结 5 1865
执念已碎
执念已碎 2021-01-30 18:06

What\'s the easiest way to create an array of structs in Cocoa?

5条回答
  •  我在风中等你
    2021-01-30 18:59

    It is easier to use class, but what if you need to work with C and objective c structs like CGRect or others. I've tried to use NSValue,but it work strange...:

    CGRect rect =CGRectMake(20,220,280,30);
    NSValue* rectValue = [NSValue valueWithCGRect:rect];
    NSArray *params1;
    params1= [NSArray arrayWithObjects:rectValue,nil];
    

    But,I can get CGRect value only as:

    CGRect cgr = [[params1 objectAtIndex:0] CGRectValue];
    

    When I use this:

    id currentVal = [params1 objectAtIndex:0];  
    void* buffer;
    buffer=[currentVal pointerValue];
    

    it causes the error...


    problem solved here

提交回复
热议问题