Skip to content

Commit

Permalink
New AnyObject system!
Browse files Browse the repository at this point in the history
Just parse any var fetch from the plist as "as Type" to get it in the correct way, like data, string, number, array...
For arrays and dictionaries:
var value = plistGet(...)
value = value.mutableCopy()
  • Loading branch information
portapipe committed Nov 27, 2014
1 parent a9a59d9 commit b80583b
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,34 @@ ENGLISH
## Usage

### Swift Version
Get values (return NSString):
Get values (return AnyObject):
<pre>
<code>
plistGet(key:String, forPlistNamed:String) -> NSString
plistGet(key:String, forPlistNamed:String) -> AnyObject
</code>
</pre>

Set value for key:
<pre>
<code>
plistSet(newValue:String, forKey:String, inPlistNamed:String)
plistSet(newValue:AnyObject, forKey:String, inPlistNamed:String)
</code>
</pre>

With Arrays and Dictionaries you have to set the var to a .mutableCopy() of it before setting it:
<pre>
<code>
var value = plistGet(...)
value = value.mutableCopy()
</code>
</pre>

---
### Example - Swift Version

Fetching the name of background music from the 'settings.plist' file into the project:

var stringFromPlist : NSString = plistGet("settings", "backgroundMusic")
var stringFromPlist : NSString = plistGet("settings", "backgroundMusic") as NSString


Editing the background music, saving the changes on the fly:
Expand Down Expand Up @@ -113,22 +122,30 @@ ITALIANO
Ritorna il valore passando una chiave (ritorna NSString):
<pre>
<code>
plistGet(key:String, forPlistNamed:String) -> NSString
plistGet(key:String, forPlistNamed:String) -> AnyObject
</code>
</pre>

Setta un valore nel file per la chiave passata:
<pre>
<code>
plistSet(newValue:String, forKey:String, inPlistNamed:String)
plistSet(newValue:AnyObject, forKey:String, inPlistNamed:String)
</code>
</pre>

Con Array e Dictionary devi settare la variabile in una versione .mutableCopy() prima di poterli modificare:
<pre>
<code>
var value = plistGet(...)
value = value.mutableCopy()
</code>
</pre>
---
### Esempio - Versione Swift

Estraiamo il nome della musica di sottofondo dal file 'settaggi.plist' presente nel progetto:

var stringFromPlist : NSString = plistGet("settings", "backgroundMusic")
var stringFromPlist : NSString = plistGet("settings", "backgroundMusic") as NSString


Modifichiamo ora la musica di sottofondo, salvando subito il cambiamento:
Expand Down

0 comments on commit b80583b

Please sign in to comment.