One of the most rewarding experiences you can have as a developer
is to teach young people to program.
If you ever grow jaded by how fundamentally destroyed all software is,
There is nothing like looking at a concept as a recursion
click for the first time
to compensate for the world's fatigue.
My favorite way to introduce the concept of programming
is to put all the ingredients for a peanut butter and jelly sandwich
and ask the class give me instructions for assembly
as if I were a robot 🤖.
Punchline is that computer
takes each instruction as literally as possible,
often with unexpected results.
Ask the robot to "put peanut butter on the bread",
and you can end up with an unopened jar of jif
flattering and erm of Wonder Bread.
Do not forget to specify which part of the bread to be applied to the gel?
Do not be surprised if it ends on the outer crust.
And so on.
Children love it.
The lesson to break down a complex process in discrete steps
is a great enclosure of programming.
And the malicious correspondence from lack of specificity
echo analogy of "programming as wish to create"
from our article about
numericCast (_ 🙂 .
But let's take the metaphor one step further,
and imagine it instead of ordering a single robot
make a sandwich,
You write instructions for a thousand different robots.
Big and small, fast and slow;
some have 4 arms instead of 2,
others swing in the air,
maybe somebody read everything in reverse.
Think about what would happen if more robots tried to make a sandwich
Or imagine your instructions
can be read by robots that will not be built for another 40 years,
on which peanut butter is packed in capsules
and jelly comes exclusively like a gas.
It's like what it's like to interact with a file system.
The only chance we have to make something that works
is to exploit the abstraction power.
On Apple platforms,
This functionality is provided by the foundation's framework
We can not possibly cover all that is to know
about working with file systems in a single article,
so this week,
Let's take a look at the operations you're most likely to perform
When you build an app.
File provides an easy way to create, read, move, copy and delete
both files and directories,
whether on local or network drives or iCloud ubiquitous containers.
The common currency for all these operations is paths and file addresses.
Trails and File Addresses
Objects on the file system can be identified in some different ways.
For example, each of the following represents
location of the same text document:
- File Address:
file: ///Users/NSHipster/Documents/article.md [1
Trails are slant-bounded (
/ ) strings that represent a place
in the catalog hierarchy.
File addresses are URLs with a
file: // the scheme in addition to a file path.
File Reference Addresses identify the location of a file
uses a unique identifier separated from any directory structure.
you will mostly relate to the first two,
which identifies files and directories using a relational path.
That path may be certainly
and provide full placement of a resource from the root directory,
or it may be relative
and show how to get to a resource from a given point of departure.
Absolute URLs begin with
while relative URLs begin with
./ (the current directory),
../ (parent directory), or
~ (the current user's home directory).
File has methods that accept both paths and URLs -
often with variations of the same method for both.
In general, the use of URLs is preferred for lanes,
as they are more flexible to work with.
(it's also easier to convert from a web address to a path than vice versa).
Finding Files and Directories
The first step to working with a file or directory
is to find it on the file system.
Standard locations vary on different platforms,
so rather than manually constructing paths like
/ System or
~ / Documents ,
url (for: in: appropriate
to find the right place for what you want.
The first parameter takes one of the values specified by
These determine what kind of standard directory you are looking for,
such as "Documents" or "Caches."
The other parameter passes a
which determines the extent of where you are looking for.
.application may refer to
/ Programs in the local domain
. url ( to : documentDirectory
in .:. userDomainMask
appropriateFor : nil
skape : false )