{"_id":"55d33d90b9ef4435006dec70","project":"5463e333447e0a100024a087","version":{"_id":"5463e333447e0a100024a08a","project":"5463e333447e0a100024a087","__v":6,"createdAt":"2014-11-12T22:46:11.486Z","releaseDate":"2014-11-12T22:46:11.486Z","categories":["5463e333447e0a100024a08b","54645c365871e90800f50151","547b1c5a4366a708001b3b50","547b1cdf4366a708001b3b5a","54e3bef8464a9c3700f7ca67","54ec651d7ab3172d00c01ab7"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":7,"category":{"_id":"5463e333447e0a100024a08b","project":"5463e333447e0a100024a087","pages":["5463e334447e0a100024a08d","54646a285871e90800f50174","54667e7af2b6390800dfd82a","54679c8c98b6840800268982","54679d8498b6840800268987","546a2ed0394c861a00c3a413","546b6a4862515a14007ebbba","547b1c2e7eec0f080099e1dd","55d33d90b9ef4435006dec70","56570c764d1c720d001f51bb"],"version":"5463e333447e0a100024a08a","__v":10,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-11-12T22:46:11.951Z","from_sync":false,"order":1,"slug":"documentation","title":"Documentation"},"user":"54639d06447e0a1000249f7f","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-08-18T14:13:36.616Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":999,"body":"PLIST's allow you to read and write data to and from a file with an XML layout.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Reading A PLIST From The Resources Folder\"\n}\n[/block]\nFirst of all make sure you have put the **PLIST** file in the resources folder in a similar way as you would with images and audio files and add it to your project.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"__String *filename = __String::create( \\\"Level.plist\\\");\\n__Dictionary *plistPattern = __Dictionary::createWithContentsOfFile( filename->getCString( ) );\\n\\nlog( \\\"Int Value: %i\\\", plistPattern->valueForKey( \\\"KeyNameInt\\\" )->intValue( ) );\\nlog( \\\"Float Value: %f\\\", plistPattern->valueForKey( \\\"KeyNameFloat\\\" )->floatValue( ) );\\nlog( \\\"String Value: %s\\\", plistPattern->valueForKey( \\\"KeyNameString\\\" )->getCString( ) );\\nlog( \\\"Bool True Value: %d\\\", plistPattern->valueForKey( \\\"KeyNameBoolTrue\\\" )->boolValue( ) );\\nlog( \\\"Bool False Value: %d\\\", plistPattern->valueForKey( \\\"KeyNameBoolFalse\\\" )->boolValue( ) );\",\n      \"language\": \"cplusplus\",\n      \"name\": \"Cocos2d-x C++\"\n    },\n    {\n      \"code\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\\n<!DOCTYPE plist PUBLIC \\\"-//Apple//DTD PLIST 1.0//EN\\\" \\\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\\\">\\n<plist version=\\\"1.0\\\">\\n<dict>\\n\\t<key>KeyNameInt</key>\\n\\t<integer>10</integer>\\n\\t<key>KeyNameFloat</key>\\n\\t<real>20.45</real>\\n\\t<key>KeyNameString</key>\\n\\t<string>Hello World!</string>\\n\\t<key>KeyNameBoolTrue</key>\\n\\t<true/>\\n\\t<key>KeyNameBoolFalse</key>\\n\\t<false/>\\n</dict>\\n</plist>\",\n      \"language\": \"xml\",\n      \"name\": \"PLIST File Used\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Writing To A PLIST On The Device\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"__Dictionary *myDictionary = __Dictionary::create( );\\n\\nmyDictionary->setObject( __Integer::create( 4 ), __String::create( \\\"KeyNameInt\\\" )->getCString( ) );\\nmyDictionary->setObject( __Float::create( 5.67 ), __String::create( \\\"KeyNameFloat\\\" )->getCString( ) );\\nmyDictionary->setObject( __String::create( \\\"Hello World!\\\" ), __String::create( \\\"KeyNameString\\\" )->getCString( ) );\\nmyDictionary->setObject( __Bool::create( true ), __String::create( \\\"KeyNameBoolTrue\\\" )->getCString( ) );\\n\\n__String *fileName = __String::create( \\\"Filename.plist\\\" );\\n__String *filepath = __String::createWithFormat( \\\"%s%s\\\", FileUtils::getInstance( )->getWritablePath( ).c_str( ), fileName->getCString( ) );\\n\\n// Save your dictionary to a file\\nmyDictionary->writeToFile( filepath->getCString( ) );\",\n      \"language\": \"cplusplus\",\n      \"name\": \"Cocos2d-x C++\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Reading A PLIST That Has Been Saved On A Device\"\n}\n[/block]\nThis and the previous section go hand in hand.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"__String *fileName = __String::create( \\\"Filename.plist\\\" );\\n__String *filepath = __String::createWithFormat( \\\"%s%s\\\", FileUtils::getInstance( )->getWritablePath( ).c_str( ), fileName->getCString( ) );\\n\\n__Dictionary *plistPattern = __Dictionary::createWithContentsOfFile( filepath->getCString( ) );\\n\\nlog( \\\"Int Value: %i\\\", plistPattern->valueForKey( \\\"KeyNameInt\\\" )->intValue( ) );\\nlog( \\\"Float Value: %f\\\", plistPattern->valueForKey( \\\"KeyNameFloat\\\" )->floatValue( ) );\\nlog( \\\"String Value: %s\\\", plistPattern->valueForKey( \\\"KeyNameString\\\" )->getCString( ) );\\nlog( \\\"Bool True Value: %d\\\", plistPattern->valueForKey( \\\"KeyNameBoolTrue\\\" )->boolValue( ) );\\nlog( \\\"Bool False Value: %d\\\", plistPattern->valueForKey( \\\"KeyNameBoolFalse\\\" )->boolValue( ) );\",\n      \"language\": \"cplusplus\",\n      \"name\": \"Cocos2d-x C++\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"plist","type":"basic","title":"PLIST"}
PLIST's allow you to read and write data to and from a file with an XML layout. [block:api-header] { "type": "basic", "title": "Reading A PLIST From The Resources Folder" } [/block] First of all make sure you have put the **PLIST** file in the resources folder in a similar way as you would with images and audio files and add it to your project. [block:code] { "codes": [ { "code": "__String *filename = __String::create( \"Level.plist\");\n__Dictionary *plistPattern = __Dictionary::createWithContentsOfFile( filename->getCString( ) );\n\nlog( \"Int Value: %i\", plistPattern->valueForKey( \"KeyNameInt\" )->intValue( ) );\nlog( \"Float Value: %f\", plistPattern->valueForKey( \"KeyNameFloat\" )->floatValue( ) );\nlog( \"String Value: %s\", plistPattern->valueForKey( \"KeyNameString\" )->getCString( ) );\nlog( \"Bool True Value: %d\", plistPattern->valueForKey( \"KeyNameBoolTrue\" )->boolValue( ) );\nlog( \"Bool False Value: %d\", plistPattern->valueForKey( \"KeyNameBoolFalse\" )->boolValue( ) );", "language": "cplusplus", "name": "Cocos2d-x C++" }, { "code": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>KeyNameInt</key>\n\t<integer>10</integer>\n\t<key>KeyNameFloat</key>\n\t<real>20.45</real>\n\t<key>KeyNameString</key>\n\t<string>Hello World!</string>\n\t<key>KeyNameBoolTrue</key>\n\t<true/>\n\t<key>KeyNameBoolFalse</key>\n\t<false/>\n</dict>\n</plist>", "language": "xml", "name": "PLIST File Used" } ] } [/block] [block:api-header] { "type": "basic", "title": "Writing To A PLIST On The Device" } [/block] [block:code] { "codes": [ { "code": "__Dictionary *myDictionary = __Dictionary::create( );\n\nmyDictionary->setObject( __Integer::create( 4 ), __String::create( \"KeyNameInt\" )->getCString( ) );\nmyDictionary->setObject( __Float::create( 5.67 ), __String::create( \"KeyNameFloat\" )->getCString( ) );\nmyDictionary->setObject( __String::create( \"Hello World!\" ), __String::create( \"KeyNameString\" )->getCString( ) );\nmyDictionary->setObject( __Bool::create( true ), __String::create( \"KeyNameBoolTrue\" )->getCString( ) );\n\n__String *fileName = __String::create( \"Filename.plist\" );\n__String *filepath = __String::createWithFormat( \"%s%s\", FileUtils::getInstance( )->getWritablePath( ).c_str( ), fileName->getCString( ) );\n\n// Save your dictionary to a file\nmyDictionary->writeToFile( filepath->getCString( ) );", "language": "cplusplus", "name": "Cocos2d-x C++" } ] } [/block] [block:api-header] { "type": "basic", "title": "Reading A PLIST That Has Been Saved On A Device" } [/block] This and the previous section go hand in hand. [block:code] { "codes": [ { "code": "__String *fileName = __String::create( \"Filename.plist\" );\n__String *filepath = __String::createWithFormat( \"%s%s\", FileUtils::getInstance( )->getWritablePath( ).c_str( ), fileName->getCString( ) );\n\n__Dictionary *plistPattern = __Dictionary::createWithContentsOfFile( filepath->getCString( ) );\n\nlog( \"Int Value: %i\", plistPattern->valueForKey( \"KeyNameInt\" )->intValue( ) );\nlog( \"Float Value: %f\", plistPattern->valueForKey( \"KeyNameFloat\" )->floatValue( ) );\nlog( \"String Value: %s\", plistPattern->valueForKey( \"KeyNameString\" )->getCString( ) );\nlog( \"Bool True Value: %d\", plistPattern->valueForKey( \"KeyNameBoolTrue\" )->boolValue( ) );\nlog( \"Bool False Value: %d\", plistPattern->valueForKey( \"KeyNameBoolFalse\" )->boolValue( ) );", "language": "cplusplus", "name": "Cocos2d-x C++" } ] } [/block]