PackageDescription: Epigent File In Method(Bundle)


Epigent File In Method

Last published: November 6, 2008 by 'runar'


"File In Method" allows storing the entire binary contents of a file in a single class method. The method will answer a domain object based on the stored file. This allows for having external resources (like images and icons) included in source code control.
Using a snippet in the comment part of the method, the developer can write the file back to disk. The resource can then be edited using an external tool, e.g. a drawing tool. Another snippet updates the method based on the file on disk.


Technical Details:
The entire binary content of the file is stored as an argument to a pragma. The pragma looks like this:
- The first argument (fileInMethod:)is the file name to use.
- The second argument (creationSelector:) is the method to be called on the class (holding the method) to create the object from the binary file contents. A byte array holding the file contents is the argument to the creation method.
- The third argument (bytes:) is the entire file contents, encoded as a String.


Usage Pattern:
Methods storing files can be created on the class side of any class you want. You should use example #pngImageBasn4a08 as a template to create your own methods. To create a new "file in method" follow this pattern:

1 - Copy class method #pngImageBasn4a08 to the class side of your own class. Replace name of method and occurrences of "pngImageBasn4a08" with your own method name.
2 - Optionally, change the first argument to the pragma (fileInMethod:) to match the external file name to be used. You might keep this to match the name of the method (plus file extension), like the example does.
3 - Optionally, change the second argument to the pragma (creationSelector:) to be a class method that will create the object based on the contents of the file. The example (#pngImageBasn4a08) simply calls a method (#epigentAnswer:) which answers the byte array itself. You can call a method that for example creates an instance of Image if the file is a PNG file.

At this point you have a method containing the example PNG image file. Now use the code snippets in the method's comment to recompile this method based on file on the disk or to write the file to disk.


Released under the curl license:

COPYRIGHT AND PERMISSION NOTICE

Copyright (c) 2008, Runar Jordahl http://www.epigent.com/

All rights reserved.

Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder.