Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7002469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:55:56+00:00 2026-05-27T20:55:56+00:00

My specific question is about using URLByAppendingPathComponent but the principle will be applicable to

  • 0

My specific question is about using URLByAppendingPathComponent but the principle will be applicable to many other classes/methods and situations.

I have the following (abbreviated)code:

NSData *packageData = [[NSData alloc] initWithContentsOfURL:[myDirectoryURL URLByAppendingPathComponent:myFileURL]];

...

ret = [self.fileManager removeItemAtURL: [myDirectoryURL URLByAppendingPathComponent:myFileURL]];

So I am using NSURL:URLByAppendingPathComponent twice with the same parameters. My question is which is more efficient, doing it this way, or creating a new NSURL* and assigning the result of the call to URLByAppendingPathComponent into that and then using that as the parameter to initWithContentsOfURL and removeItemAtURL.
I presume the second method is better but as I’m quite new to iOS and ARC want to double check. (What is the lifetime of the objects that will be created by this call? I’m using ARC and I presume their lifetime is therefore to the end of the scope of the function block in which they are used.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:55:56+00:00Added an answer on May 27, 2026 at 8:55 pm

    It’s more efficient to save the URL rather than creating (and deallocating) it an extra time.

    BUT, who cares? You should be asking which is the most clear code, that you will be able to understand and maintain later. You are never going to be loading from URLs in a tight loop, where efficiency might matter.

    The DRY (don’t repeat yourself) principle suggests that you make the URL once, because you have the code in only one place. That way, if something ever changes (e.g. you need to sanitize myFileURL against attacks), you only need to make the change in one place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the title might be too generic, but I have a very specific question about
I have a question about nHibernate and filtering. I am using nHibernate 2.2 but
This is not a question about a specific framework. I am using plain php
I have a fairly specific question about concurrent programming in C. I have done
I have a quick question about encapsulating specific types with typedef . Say I
I have a question about whether or not a specific way of applying of
My question is not about a specific code snippet but more general, so please
Got a question about using mod_rewrite to redirect specific subdomains to use another domain.
Grails question: Confused about using a package to hold domain classes. I'm using Netbeans
My specific question is about ASP.NET MVC but I am sure that the answers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.