0 Replies - 742 Views - Last Post: 17 May 2016 - 05:13 AM

#1 ocbarrio  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-May 16

Save an array of keys with "true" value from a dictionary plis

Posted 17 May 2016 - 05:13 AM

Hi to all!

This is my first time here, and I want to ask for a question that I can solve.

Iīm creating a JB ios 9 tweak with theos in my device. I need to save from the preferences dictionary plist an array with the keys (not values) wich have "true" as value. So all keys that are "false" were ignored, and those that are enabled are writted to a new plist.

I have all process covered and working, I can save all keys in an array as strings. But I need to filter it by itīs BOOL value.


ASNPrefs.plist (the original preferences of my tweak)

    <?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>ASNcenterEnabled</key>
            <true/>
            <key>ASNcornerEnabled</key>
            <false/>
            <key>ASNnoCenterEnabled</key>
            <true/>
            <key>ASNdepthSizeEnabled</key>
            <false/>
        </dict>
        </plist>



ASNkeys.plist (the saved array I get right now)

    <?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>ASNkeys</key>
            <array>
                <string>ASNcenterEnabled</string>
                <string>ASNcornerEnabled</string>
                <string>ASNnoCenterEnabled</string>
                <string>ASNdepthSizeEnabled</string>
            </array>
        </dict>
    </plist>


And this is (according to my original preferences plist) what I need

    <?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>ASNkeys</key>
            <array>
                <string>ASNcenterEnabled</string>
                <string>ASNnoCenterEnabled</string>
            </array>
        </dict>
    </plist>


and here is my code right now (an action inside ASNPrefs.mm file)

-(void)saveOnKeys {
NSString  *arrayPath;
NSString  *dictPath;
NSString  *origPath;

// Get path to documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

            if ([paths count] > 0)  {

                origPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"com.maat.asnPrefs.plist"];

                NSDictionary *dictOrig = [NSDictionary dictionaryWithContentsOfFile:origPath];

                NSArray *ASNKeys = [dictOrig allKeys]; //ForObject:@"true"];

                NSDictionary *dictionary = @{@"ASNKeys" : allKeys};

                // Path to save array data
                arrayPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"array.out"];

                // Path to save dictionary
                dictPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"asnKeys.plist"];

                // Write array
                [asnKeys writeToFile:arrayPath atomically:YES];

                // Write dictionary
                [dictionary writeToFile:dictPath atomically:YES];
   }
}


I found some things that might work, but I canīt figure out how to do it...
	NSSet *allOnKeys = [dictOrig keysOfEntriesPassingTest:^BOOL(id key, id obj, BOOL *stop) {
		if (![obj isEqual:@"FALSE"]) {
			return YES;
		} else {
			return NO;
		}
	}];



NSArray *allOnKeys = [dictOrig keysOfEntriesPassingTest:^BOOL(id key, id obj, BOOL *stop) {
		if (![obj isEqual:@"FALSE"]) {
			return YES;
		} else {
			return NO;
		}
	}];


NSArray *tempArray = [NSArray arrayWithObjects:@"Eezy",@"Tutorials", @"Website"];
array = [tempArray objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 2)]]; 
NSLog(@"%@",array ]);		


Thank u!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1