Difference between revisions of "Property Lists"

From GNUstepWiki
Jump to navigation Jump to search
(Added better Array example.)
(Added more information/tips, shortened warning)
Line 1: Line 1:
NOTE: '''If anything below is dead wrong, please fix immediately. It is a work in progress. I am constructing this based on my experience with GNUstep, NOT any reference documentation that may exist. I don't warrant it fit for any purpose whatsoever, nor shall I take any responsibility for any issues or losses or problems etc that may arise from its use. (Christopher Armstrong, --[[User:Quineska|ChrisArmstrong]] 08:38, 6 Jul 2005 (CEST))'''
+
NOTE: this document is still a work in progress. No responsibility is accepted for any problems arising from inaccuracies.
 
 
  
 
== Introduction ==
 
== Introduction ==
  
Property lists are used throughout GNUstep to store defaults, program settings, application meta information, etc. MacOS X uses XML based property lists, but GNUstep uses another property list implementation also (TODO: history of this style of property list).
+
Property lists are used throughout GNUstep to store defaults, program settings, application meta information, etc. MacOS X uses XML based property lists, but GNUstep uses another property list implementation also (TODO: history of this style of property list). Support for XML property lists is still wanting on some platforms; this situation should improve in the future.
  
 
They are composed of a "tree of arrays and dictionary's, which may be embedded inside each other for several layers. TODO: limits of embedding array/dictionaries inside each other.
 
They are composed of a "tree of arrays and dictionary's, which may be embedded inside each other for several layers. TODO: limits of embedding array/dictionaries inside each other.
Line 20: Line 19:
 
  }
 
  }
  
As can be seen, each key-value pair is seperated by a semi-colon. Within the pair, the key is seperated from the value with an "equals" (=) sign. The key name is arbitrary, and not put in inverted commas (""). Shown above are a (unknown type, could be some sort of string - TODO), a string, an array, a number and another dictionary  (respectively).
+
As can be seen, each key-value pair is seperated by a semi-colon. Within the pair, the key is seperated from the value with an "equals" (=) sign. The key name is arbitrary, and not put in inverted commas (""). Shown above are:  an unknown type (could be some sort of string - TODO), a string, an array, a number and another dictionary  (respectively).
  
 
== Array ==
 
== Array ==
Line 39: Line 38:
 
== Programming ==
 
== Programming ==
  
GNUstep permits such property list files (denoted with a .plist extenstion) to be loaded and subsequently used in your applications or tools. NSDictionary and NSArray are used as representations of the above in the Foundation library (gnustep-base).
+
GNUstep permits such property list files (denoted with a .plist extenstion) to be loaded and subsequently used in your applications or tools. NSDictionary and NSArray are used as representations of the above in the Foundation library (gnustep-base). Check the base API documentation for more information on working with these types programmatically.
 +
 
 +
Also, NSString can be used to turn property lists in string form to an equivalent programmatic tree. Again, see the API documentation for NSString (particularly propertyList method).
 +
 
 +
== Other tips ==
 +
 
 +
* Property lists are much like C programming, where newlines and spaces and tabs are not so important to parsing.
 +
* Some examples of property lists may include:
 +
** ~/GNUstep/System/Defaults/.GNUstepDefaults (this is your defaults file for software; be careful when editing)
 +
 
 +
 
  
 
[[Category:Development]]
 
[[Category:Development]]

Revision as of 05:25, 7 July 2005

NOTE: this document is still a work in progress. No responsibility is accepted for any problems arising from inaccuracies.

Introduction

Property lists are used throughout GNUstep to store defaults, program settings, application meta information, etc. MacOS X uses XML based property lists, but GNUstep uses another property list implementation also (TODO: history of this style of property list). Support for XML property lists is still wanting on some platforms; this situation should improve in the future.

They are composed of a "tree of arrays and dictionary's, which may be embedded inside each other for several layers. TODO: limits of embedding array/dictionaries inside each other.

Dictionary

A dictionary is a list of key-value pairs, where each item in the list has a name associated with it (key) and another type (value), which could be another dictionary, an array or often a string. It programmatically corresponds to NSDictionary/NSMutableDictionary. They take the following syntax:

{
   KeyName1 = Value1;
   AnotherKeyName = "Value2";
   Something = ( "ArrayItem1", "ArrayItem2", "ArrayItem3" );
   Key4 = 0.10;
   KeyFive = { Dictionary2Key1 = "Something"; AnotherKey = "Somethingelse"; };
}

As can be seen, each key-value pair is seperated by a semi-colon. Within the pair, the key is seperated from the value with an "equals" (=) sign. The key name is arbitrary, and not put in inverted commas (""). Shown above are: an unknown type (could be some sort of string - TODO), a string, an array, a number and another dictionary (respectively).

Array

An array is a list of values, each of the same type (often arrays or dictionaries). Programmatically, it uses NSArray/NSMutableArray. It takes a syntax similar to the following:

( Value1, Value2, Value3, Value4 )
or
( Value1, Value2, Value3, Value4 )

Each value is seperated by commas. By the technical definition of an array, each value is of the same type (but I believe GNUstep permits different types TODO: check this).

Programming

GNUstep permits such property list files (denoted with a .plist extenstion) to be loaded and subsequently used in your applications or tools. NSDictionary and NSArray are used as representations of the above in the Foundation library (gnustep-base). Check the base API documentation for more information on working with these types programmatically.

Also, NSString can be used to turn property lists in string form to an equivalent programmatic tree. Again, see the API documentation for NSString (particularly propertyList method).

Other tips

  • Property lists are much like C programming, where newlines and spaces and tabs are not so important to parsing.
  • Some examples of property lists may include:
    • ~/GNUstep/System/Defaults/.GNUstepDefaults (this is your defaults file for software; be careful when editing)