How read PLIST into NSArray?
Quote from Forum Archives on December 8, 2011, 6:47 amPosted by: fbcocoa.bw <fbcocoa.bw@...>
Aren't PLISTs usually dicts? I think Safari webarchives are. Anyhow, my broadband is down, so I'm keying this on iPhone. Not sure if it's what you're after.include "ConsoleWindow"
include "Tlbx CFURLAccess.incl"
include "Tlbx CFPropertyList.incl"local fn CreatePLISTDict( url as CFURLRef ) as CFDictionaryRef
dim as CFDataRef dataRef
dim as CFDictionaryRef dict : dict = NULLlong if ( fn CFURLCreateDataAndPropertiesFromResource( _kCFAllocatorDefault, url, @dataRef, NULL, 0, NULL ) )
long if ( dataRef )
dict = (CFDictionaryRef)fn CFPropertyListCreateFromXMLData( _kCFAllocatorDefault, dataRef, 0, NULL )
CFRelease( dataRef )
end if
end if
end fn = dictdim as CFURLRef url
dim as CFDictionaryRef dictlong if ( files$( _CFURLRefOpen,,, url )
dict = fn CreatePLISTDict( url )
long if ( dict)
fn ConsolePrintCFType( dict )
CFRelease( dict )
end if
end ifPhew! That was hard work.
Bernie
[top-posted from my iPhone]On 8 Dec 2011, at 10:34, Robert Covington <[email protected]> wrote:
>
> Can anyone point out how I can read an XML PLIST data object into an NSArray?
>
> NSArray * archiveArray = [NSArray arrayWithObject:(NSData *)xmlData];
>
> arrayCount = [archiveArray count];
>
> NSLog(@"My Array Count = %i", arrayCount);
>
> Well, gives 1, as you'd expect, I guess...since there's one object, xmlData, though it has kazillions in the PLIST itself.
>
> Is there anything which will automagically put the dang thing into the array already sorted, and elemented? To where I can then extract the image data?
>
> NSDictionary?
>
> This is from a Safari Web Archive, read from disk, saved out as XML (or in this case, just read into an array, I don't need to save it first, do I?
>
> (Safari archives are in binary, I convert to XML...)
>
> rc
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
Posted by: fbcocoa.bw <fbcocoa.bw@...>
include "ConsoleWindow"
include "Tlbx CFURLAccess.incl"
include "Tlbx CFPropertyList.incl"
local fn CreatePLISTDict( url as CFURLRef ) as CFDictionaryRef
dim as CFDataRef dataRef
dim as CFDictionaryRef dict : dict = NULL
long if ( fn CFURLCreateDataAndPropertiesFromResource( _kCFAllocatorDefault, url, @dataRef, NULL, 0, NULL ) )
long if ( dataRef )
dict = (CFDictionaryRef)fn CFPropertyListCreateFromXMLData( _kCFAllocatorDefault, dataRef, 0, NULL )
CFRelease( dataRef )
end if
end if
end fn = dict
dim as CFURLRef url
dim as CFDictionaryRef dict
long if ( files$( _CFURLRefOpen,,, url )
dict = fn CreatePLISTDict( url )
long if ( dict)
fn ConsolePrintCFType( dict )
CFRelease( dict )
end if
end if
Phew! That was hard work.
Bernie
[top-posted from my iPhone]
On 8 Dec 2011, at 10:34, Robert Covington <[email protected]> wrote:
>
> Can anyone point out how I can read an XML PLIST data object into an NSArray?
>
> NSArray * archiveArray = [NSArray arrayWithObject:(NSData *)xmlData];
>
> arrayCount = [archiveArray count];
>
> NSLog(@"My Array Count = %i", arrayCount);
>
> Well, gives 1, as you'd expect, I guess...since there's one object, xmlData, though it has kazillions in the PLIST itself.
>
> Is there anything which will automagically put the dang thing into the array already sorted, and elemented? To where I can then extract the image data?
>
> NSDictionary?
>
> This is from a Safari Web Archive, read from disk, saved out as XML (or in this case, just read into an array, I don't need to save it first, do I?
>
> (Safari archives are in binary, I convert to XML...)
>
> rc
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>