Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
[[NSBundle mainBundle] bundlePath] equivalent on OSX?
I get 'nil' printed in the console. How can I easily load a plist that is "in my bundle"?
I developed for Mac for years before iOS came along.
That code should work.
Break it down and use a separate variable for each step.
Get the main bundle.
Use that to get the bundle path.
Then use THAT to build your full path to your file.
Step through the code in the debugger and check the result of each step.
My guess is that it's the call to arrayWithContentsOfFile: that's failing. That will fail if the file you're trying to read is not a well formed plist file. THAT will happen if any of the items in the array are not "property list" objects. That is the exact same thing that will happen in iOS.
Regards,
Duncan C WareTo
Animated GIF created with Face Dancer, available for free in the app store.
I think im having the same problem, did you manage to fix the problem?
I'm porting my game to the mac, it is going ok but I have hit a problem I can't seem to fix.
In the game I save all the levels into pList from our external editor and then load them into the game using the following code, which works great on iOs, but on OSX it just doesn't find the files.
The output from that NSLog reads as follows - Final Path = /Users/daviddeacon/Library/Developer/Xcode/DerivedData/GameMac-bphkstcwuqklgxbgdhezeutagblu/Build/Products/Release/GameMac.app/L1101.plist
I started developing on iOS first so haven't got a base knowledge of the differences between the to platforms, Is the mainBundle path much different?
I think im having the same problem, did you manage to fix the problem?
I'm porting my game to the mac, it is going ok but I have hit a problem I can't seem to fix.
In the game I save all the levels into pList from our external editor and then load them into the game using the following code, which works great on iOs, but on OSX it just doesn't find the files.
The output from that NSLog reads as follows - Final Path = /Users/daviddeacon/Library/Developer/Xcode/DerivedData/GameMac-bphkstcwuqklgxbgdhezeutagblu/Build/Products/Release/GameMac.app/L1101.plist
I started developing on iOS first so haven't got a base knowledge of the differences between the to platforms, Is the mainBundle path much different?
Thanks, David
The path will have different subdirectories in it, yes. As long as you are not getting nil, you should be fine.
You might want to use the NSBundle method pathForResource:ofType: instead of constructing a path yourself. That takes care of navigating into the bundle and handing you back a path to the file you ask for.
Regards,
Duncan C WareTo
Animated GIF created with Face Dancer, available for free in the app store.
Replies
That code should work.
Break it down and use a separate variable for each step.
- Get the main bundle.
- Use that to get the bundle path.
- Then use THAT to build your full path to your file.
Step through the code in the debugger and check the result of each step.My guess is that it's the call to arrayWithContentsOfFile: that's failing. That will fail if the file you're trying to read is not a well formed plist file. THAT will happen if any of the items in the array are not "property list" objects. That is the exact same thing that will happen in iOS.
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI think im having the same problem, did you manage to fix the problem?
I'm porting my game to the mac, it is going ok but I have hit a problem I can't seem to fix.
In the game I save all the levels into pList from our external editor and then load them into the game using the following code, which works great on iOs, but on OSX it just doesn't find the files.
iOS code -
The output from that NSLog reads as follows -
Final Path = /Users/daviddeacon/Library/Developer/Xcode/DerivedData/GameMac-bphkstcwuqklgxbgdhezeutagblu/Build/Products/Release/GameMac.app/L1101.plist
I started developing on iOS first so haven't got a base knowledge of the differences between the to platforms, Is the mainBundle path much different?
Thanks, David
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeYou might want to use the NSBundle method pathForResource:ofType: instead of constructing a path yourself. That takes care of navigating into the bundle and handing you back a path to the file you ask for.
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome