small medium large xlarge

Generic-user-small
27 Dec 2010, 15:11
Shera Schneider (2 posts)

The shopping list program works exactly as explained.

But first in NSDocument, this method shows up in the section listed as “Deprecated Methods”, so what method would be better to use? I understand that the book is just explaining the saving of files in the easiest form but I am just curious as to what I will eventually need to know so that I can look for more information.

Second: when I save my shopping list from my shopping list program I get the icon that is used for Accessibility stuff. It seems that my shopping list is automatically saved with the extension of “.???” used for Accessibility. When I try to put a .txt on the end, the save option yells at me saying that “You cannot save this document with extension.txt at the end of the name. The required extension is “.???”” I know this is trivial and I should move on, but seeing that Accessibilty icon has bothered me for 5 days now and I can’t seem to move on, trying to figure out WHY and HOW to fix it. Should it not be an icon of just a unknown type or an html icon?

I would really appreciate any insight that you may have, mostly with my first question.

Besides this little block, so far the book is great, I feel that I am learning and understanding much more than with 2 other books I tried.

-sHERA

Generic-user-small
27 Dec 2010, 18:54
Tim Isted (105 posts)

Hi there,

Deprecated Methods Which methods are you finding are marked as deprecated? The @writeToURL:ofType:error:@ and @readFromURL:ofType:error:@ methods should be fine under 10.6.

There are very similar methods (@writeToURL:ofType:@ and @readFromURL:ofType:@) that are deprecated from 10.4 onwards; note the lack of an @error:@ for these compared with the above.

Saving Documents in a format to be reopened In order to save the document with a file extension and configure it to reopen automatically with the Shopping List application, you’ll need to make a modification to the application’s @Info.plist@ file (this will likely be called @Shopping_List-Info.plist@) involving UTI (Universal Type Identifiers).

As a “quick” fix to get it working asap, open the Shopping List project in Xcode, then right-click on the @Shopping_List-Info.plist@ file and choose Open As > Source Code File.

The file will be displayed as raw XML; you’ll see it start off as something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>English</string>

... etc

Find the portion that looks like this:

	<key>CFBundleDocumentTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeExtensions</key>
			<array>
				<string>????</string>
			</array>
			<key>CFBundleTypeIconFile</key>
			<string></string>
			<key>CFBundleTypeName</key>
			<string>DocumentType</string>
			<key>CFBundleTypeOSTypes</key>
			<array>
				<string>????</string>
			</array>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>NSDocumentClass</key>
			<string>MyDocument</string>
		</dict>
	</array>

and change it to look like this:

	<key>CFBundleDocumentTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeExtensions</key>
			<array>
				<string>shoppinglist</string>
			</array>
			<key>CFBundleTypeIconFile</key>
			<string></string>
			<key>CFBundleTypeName</key>
			<string>Shopping List Data Format</string>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>LSItemContentTypes</key>
			<array>
				<string>com.timisted.shoppingList.document</string>
			</array>
			<key>NSDocumentClass</key>
			<string>MyDocument</string>
		</dict>
	</array>

Insert a new line after that final @</array>@ line, and paste this:

	<key>UTExportedTypeDeclarations</key>
	<array>
		<dict>
			<key>UTTypeConformsTo</key>
			<array>
				<string>public.data</string>
				<string>public.content</string>
			</array>
			<key>UTTypeDescription</key>
			<string>Shopping List Document</string>
			<key>UTTypeIdentifier</key>
			<string>com.timisted.shoppingList.document</string>
			<key>UTTypeReferenceURL</key>
			<string>http://www.company.com/yourproduct</string>
			<key>UTTypeTagSpecification</key>
			<dict>
				<key>com.apple.ostype</key>
				<string>XXXX</string>
				<key>public.filename-extension</key>
				<array>
					<string>shoppinglist</string>
				</array>
			</dict>
		</dict>
	</array>

These changes set up the type of document that the application can save, and that it can open. To learn more about how this works, start with this Apple document: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Documents/Concepts/DocTypePList.html%23//apple_ref/doc/uid/20000024-BHADAGHF

If you can’t get the @plist@ file entries to work, please let me know and I’ll upload a copy somewhere that’s properly configured.

Generic-user-small
27 Dec 2010, 19:13
Shera Schneider (2 posts)

Thanks for the quick reply

I found this “– writeToURL:ofType: Deprecated in Mac OS X v10.4” The deprecate is not when I look up “– writeToURL:ofType:error” I guess since they look so much the same this is the cause of my confusion.

Thanks for the additional code of the plist, that did the trick. Strange how sometimes the most silly things like the wrong icon can stop one from moving on. I appreciate the help.

Generic-user-small
10 Mar 2011, 09:01
interpunct (1 post)

*Edit: The problem was caused by the switch to the use of an object instead of an array to hold an item’s information. The issue is addressed in the section that covers @NSCoding@. Please disregard this post.*

Hi there,

I’ve encountered another problem when saving a file from my Shopping List application by using the @writeToURL:ofType:error:@ method outlined in the book.

The application returns the following error:

bq. The document “Untitled” could not be saved as “Untitled.shoppinglist”.

This happens even though I have made the modifications to @Info.plist@ mentioned in Tim Isted’s post above.

Has anyone encountered a similar problem and managed to solve it?

— interpunct

Generic-user-small
26 Apr 2011, 10:27
trewqe1 (1 post)

good and very interesting post

You must be logged in to comment