whats the difference of copying image to folder?

Discussion in 'iOS Programming' started by blakintosh, Jan 5, 2010.

  1. blakintosh macrumors member

    Joined:
    May 26, 2008
    #1
    Ok, when I drag and drop an image to my iphone app project in xcode, it asks me if I want to make a copy.

    What's better to create a copy or just centralize it in another separate folder and when I'm done everything will be wrapped up by xcode?

    I believe that at the end there is some kind of png optimization and I don't want the unoptimized png files to stay on the app at the end because this would be useless

    thanks in advance
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Create a copy. Because otherwise when the app is deployed to a device, it won't be there. Xcode does not wrap files into an app bundle that are included by reference.
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    Hmmm, I don't think I've ever used that create a copy feature.

    I have a Resources folder in my project folder. I put all my images and other resource files in that folder. I add them to my project just like a source file. They're automatically added to the copy bundle resources build phase and end up in the bundle.

    That seems simple enough.
     
  4. blakintosh thread starter macrumors member

    Joined:
    May 26, 2008
    #4
    So you know for sure that the images will be added at the end even if I don't copy them?

    thanks!
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    Works for me.

    If you look at the Copy Bundle Resources build phase in your project you'll see the files that it's going to copy into your bundle. And of course you can open up the app bundle in your build folder to look at it.
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    PhoneyDeveloper, could you elaborate on how you are adding files to your Resources folder? Just so I can be clear and help to understand the difference between your approach and what blakintosh is probably doing. Are you doing this via Finder or Xcode? If Xcode, are you using Add > Existing Files...?
     
  7. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    I add the image files to the Resources folder in the Finder. I then add those files to the project by dragging them in from the Finder.

    What does the create a copy do?
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Just like what it says: it creates a copy of the file in your bundle rather than simply referencing it from another location (which is something you would normally do for frameworks, for example). If you use Add > Existing Files... and check the "Copy items into destination group's folder (if needed)" option, Xcode creates a copy of the file in your bundle and adds the file to the project in one step. (Also, it leaves a copy of the file in the original location, of course).
     
  9. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #9
    OK, I see.

    When you say bundle you really mean project folder.

    I'd never want it to do that. I almost never want an image file to be at the root of my project folder. That's what the Resources folder is for.
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    Yeah, that's right. What resides in the project folder gets put into the bundle upon compilation, of course.

    Yeah, it would be nice if Xcode better handled adding files to subfolders of the project folder. I wish it could better detect when a group is also a folder. When I right-click on the Resources group (which is also a folder) and add files, I'd love for them to be added to the folder as well.
     
  11. TodVader macrumors 6502a

    TodVader

    Joined:
    Sep 27, 2005
    Location:
    Quebec, Canada
    #11
    I just drag images from finder to the resource folder in xcode and check the "copy". It adds it to the Resources folder of my app and keeps the original file.

    I thought everyone did it like that...?
     
  12. blakintosh thread starter macrumors member

    Joined:
    May 26, 2008
    #12
    thats what I think, so it just came to my mind that why does that option of "do you want a copy or not" exists and what is the difference at the end when you finish your app
     
  13. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #13
    Actually, that's not exactly correct. And I must apologize!; upon further investigation I realize I've been confusing the matter even further with my talk of groups vs. folders. An (iPhone) project, by default, contains a Resources group but not a Resources folder. So, when you move or copy files to Resources in Xcode, it is not actually placing them in a subfolder in your project folder; they're just added at the project folder level.

    I seem to recall that if you wanted an actual subfolder in your project, you will have some extra work to do and then, I believe, you'll need to make sure all your references to files in the subfolder are adjusted accordingly. Actual folders will show up with blue icons in Xcode, groups are tan-colored. In the end, unless you're really anal about your file organization within your project folder, it's extra effort for little return.

    Hope that helps and again, sorry, for adding to the confusion.
     
  14. TodVader macrumors 6502a

    TodVader

    Joined:
    Sep 27, 2005
    Location:
    Quebec, Canada
    #14
    I guess so. I never go check my files with finder. If I want one in Finder, I'll right click on it in xcode and click on "Reveal in finder"

    It always worked fine like that for me. I'm reaalllly not anal about file placement, I'd rather give more time to actually programming :)
     

Share This Page