Article Preview
Buy Now
FEATURE
Bundle It
Save your document as a MacOS Package
Issue: 20.4 (July/August 2022)
Author: Marc Zeedar
Author Bio: Marc taught himself programming in high school when he bought his first computer but had no money for software. He's had fun learning ever since.
Article Description: No description available.
Article Length (in bytes): 14,343
Starting Page Number: 26
Article Number: 20403
Resource File(s):
project20403.zip Updated: 2022-06-30 18:36:07
Related Link(s): None
Excerpt of article text...
Bundles are cool. They're basically a collection of files inside a folder that appear to be a single file to the user. Mac applications are bundles, for instance, and can include executable code, pictures, text, data, fonts, and other kinds of resources. But to the user, it's just a single application file.
You can also use the same bundle concept as a document format. Say you've written a program that saves a document that contains multiple pieces of text and pictures. You really want the user to see only a single file, not a bunch of text and picture files. You could store everything in an XML file, with the pictures encoded as binary data, but that's complicated and a hassle. It's also not too user-friendly as XML isn't very human-readable. A better approach is to save the document as a
bundle (more accurately called apackage as Apple thinks bundles contain code: seehttps://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AboutBundles/AboutBundles.html
). Inside the bundle are separate files for each text and photo, but the user sees just a single file.Unfortunately, bundles/packages are an Apple thing, so they're only available on MacOS and iOS. If your project needs to be cross-platform and you want the same concept, you'd probably need to use a .zip file archive (which can contain multiple files inside it). Reading and saving .zip files is complex, though, requiring a plugin or extra code, and not necessary if your project is going to be Mac- or iOS-only.
Creating a Bundle
So how do you go about creating a bundle? Years ago I had to do it with a special system call. That method broke with operating system upgrades as Apple depreciated that way of doing things.
Now bundles are basically created automatically by the system—if you set things up just right.
...End of Excerpt. Please purchase the magazine to read the full article.