Question

In simulator i will get the obj files from bundle:

NSArray *myArray = [[NSBundle mainBundle] pathsForResourcesOfType:@"obj" inDirectory:nil];

In simulator the obj files are printed alphabetical order:

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**banana.obj**,

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**plane3.obj**,

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**wolverine.obj**,

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**Wteapot.obj**,

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**XBODY.obj**,

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**YLID.obj**
)

But ipad the obj files are not printed alphabetical order.

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**wolverine.obj,**

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app**/**Wteapot.obj**,**

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**plane3.obj**,

What is the problem?

Was it helpful?

Solution 2

I think some of your obj file name starting character is in capital letter. just change those file names starting character is in small letter.

OTHER TIPS

Apple Document of pathsForResourcesOfType:inDirectory: says that:

An array containing the full pathnames for all bundle resources matching the specified criteria. This method returns an empty array if no matching resource files are found.

It means Apple doesn't say that it will give you path in any particular order but if you need it in some order than you can sort by yourself.

NSArray *sorted = [myArray sortedArrayUsingComparator:^NSComparisonResult(NSString *str1, NSString *str2) 
{
    return [s1 localizedCaseInsensitiveCompare:s2];
}];

So now you have sorted NSArray of all paths.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top