How can I compare two Version number strings?
For example: 3.1.1 and 3.1.2.5.4
Now I need to find out if 3.1.2.5.4 is higher than 3.1.1 but I don't know how to do this.
Can anybody help me?
Thanks in advance!
Sample Code :
NSString* v1 = #"3.1.1";
NSString* v2 = #"3.1.2.5.4";
if ([v1 compare:v2 options:NSNumericSearch] == NSOrderedDescending) {
NSLog(#"%# is greater than %#",v1,v2);
}
From the Apple Documentation for Comparing and sorting strings.
Yes, you can compare the versions, please refer the code below:
public class Comparision {
string ver1, ver2;
public static void main(String args[]){
string ver1Split[] = ver1.split('.');
string ver2Split[] = ver2.split('.');
for (int i = 0; i < ver1Split.length; ++i) {
if (ver2Split == i) {
return ver1 + " is larger";
}
if (ver1Split[i] == ver2Split[i]) {
continue;
}
else if (ver1Split[i] > ver1Split[i]) {
return ver1 + " is larger";
}
else {
return ver2 + " is larger";
}
if (ver1Split.length != ver2Split.length) {
return ver2 + " is larger";
}
return "versions are equal";
}
}
Objective-C:
- (BOOL)isVersion:(NSString *)arg1 higherThan:(NSString *)arg2 {
NSMutableString * v1 = arg1.mutableCopy;
NSMutableString * v2 = arg2.mutableCopy;
NSMutableArray * parts1 = [v1 componentsSeparatedByString:#"."].mutableCopy;
NSMutableArray * parts2 = [v2 componentsSeparatedByString:#"."].mutableCopy;
if (parts1.count > parts2.count) {
NSInteger diff = parts1.count - parts2.count;
for (NSInteger i = diff; i<parts1.count; i++) {
[v2 appendString:#".0"];
}
} else if (parts1.count < parts2.count){
NSInteger diff = parts2.count - parts1.count;
for (NSInteger i = diff; i<parts2.count; i++) {
[v1 appendString:#".0"];
}
}
parts1 = [v1 componentsSeparatedByString:#"."].mutableCopy;
parts2 = [v2 componentsSeparatedByString:#"."].mutableCopy;
NSInteger j = 0;
for (NSString * num1 in parts1) {
NSString * num2 = parts2[j];
if(num1.integerValue > num2.integerValue){
//break;
return YES;
} else if (num1.integerValue < num2.integerValue) {
//break;
return NO;
} else {
// ==
}
j++;
}
return NO;
}
Unit test:
- (void)test_isHigherFunc {
XCTAssert([self isVersion:#"4.1.2.1" higherThan:#"4.1.2.0"]);
XCTAssertFalse([self isVersion:#"4.1.2.0" higherThan:#"4.1.2.0"]);
XCTAssert([self isVersion:#"4.1.2.0" higherThan:#"4.1.1.0"]);
XCTAssertFalse([self isVersion:#"3.1.2.0" higherThan:#"4.1.1.0"]);
XCTAssertFalse([self isVersion:#"4.2.2.0" higherThan:#"4.3.1.0"]);
XCTAssert([self isVersion:#"5.2" higherThan:#"4.3.1.0"]);
XCTAssertFalse([self isVersion:#"6.2" higherThan:#"7.3.1.0"]);
XCTAssert([self isVersion:#"6.2" higherThan:#"5"]);
XCTAssert([self isVersion:#"6.2.0" higherThan:#"5.9"]);
XCTAssert([self isVersion:#"1.1.1.1.1.1.1.1" higherThan:#"1.1.1.1.1.1.1.0"]);
XCTAssert([self isVersion:#"2.0" higherThan:#"1"]);
}
Related
I'm trying to build a game in iOS and am currently using Objective-C. The problem I'm running into is Z-sorting different enemy and player nodes. This is my current code for Z-sorting just one enemy type, and I am only copying this code to z-sort every different type of enemy (Mob). This is leading to ALOT of code that all does essentially the same thing for different objects. The only way I know how to fix this problem is by using template functions, but Objective-C doesn't support that to my knowledge. There has to be a better way...
// If two monsters are standing on the same cell, we need to z sort them based on position
// south-western most body will be closest to the "camera" from players perspective
-(void) zSortMobs {
int i = 0;
int j = 0;
for (i = 0; i < self.maxMobs; i++) {
Mob * mob = [self.mobs objectAtIndex: i];
if (mob.state != 0) {
for (j = 0; j < self.maxMobs; j++) {
Mob * mob2 = [self.mobs objectAtIndex: j];
if (mob2.state != 0) {
if (mob != mob2) {
if (mob.z == mob2.z) {
if (mob.y < mob2.y) {
mob.z++;
}
else if (mob.y == mob2.y) {
if (mob.x < mob2.x) {
mob.z++;
}
else {
mob2.z++;
}
}
else {
mob2.z++;
}
}
}
[mob setZPosition: mob.z];
[mob2 setZPosition: mob2.z];
}
}
for (j = 0; j < self.maxTanks; j++) {
Tank * tank = [self.tanks objectAtIndex: j];
if (tank.state != 0) {
if (mob.z == tank.z) {
if (mob.y < tank.y) {
mob.z++;
}
else if (mob.y == tank.y) {
if (mob.x < tank.x) {
mob.z++;
}
else {
tank.z++;
}
}
else {
tank.z++;
}
}
[mob setZPosition: mob.z];
[tank setZPosition: tank.z];
}
}
if (mob.z == self.gameScene.player.z) {
if (mob.y < self.gameScene.player.y) {
mob.z++;
}
else if (mob.y == self.gameScene.player.y) {
if (mob.x < self.gameScene.player.x) {
mob.z++;
}
else {
self.gameScene.player.z++;
}
}
else {
self.gameScene.player.z++;
}
}
[mob setZPosition: mob.z];
[self.gameScene.player setZPosition: self.gameScene.player.z];
}
}
}
I have an array of names and want to count them by having A & B prefix.
For example for this username I want my NSMutableDictionary *cellNum to return the count of names starting with each alphabet, like: "A":"2" & "B":"1".
#interface ...
{
NSArray *users;
NSMutableDictionary *cellNum;
}
#implementation ...
{
users = #[#"Ali",#"Armita",#"Babak"];
for (int i=0;i<users.count;i++)
{
if ( [users[i] hasPrefix:#"A"] )
{
cellNum[#"a"] = #([cellNum[#"a"] intValue]+1);
}
else
{
cellNum[#"b"] = #([cellNum[#"b"] intValue]+1);
}
}
}
Try using this code:
NSMutableDictionary *cellNum = [NSMutableDictionary dictionary];
[cellNum setObject:#(0) forKey:#"a"];
[cellNum setObject:#(0) forKey:#"b"];
NSArray* users = #[#"Ali",#"Armita",#"Babak"];
for (int i=0;i<users.count;i++)
{
if ( [users[i] hasPrefix:#"A"] ) {
cellNum[#"a"] = #([cellNum[#"a"] intValue]+1);
} else {
cellNum[#"b"] = #([cellNum[#"b"] intValue]+1);
}
}
This will surely Give you the desired result: { a = 2; b = 1; }
can anyone help me in my code. I am getting WA and m not able to rectify it plzzz
my code http://ideone.com/DkrwIg
problem link : http://www.spoj.com/problems/BRCKTS/
i am a bit doubtful in my modification function.
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
char str[40010];
struct node
{
int sum;
int minsum;
}tree[1000005];
void build(int id,int l,int r)
{
if(r-l<2)
{
if(str[l] == '(')
{
tree[id].sum = 1;
tree[id].minsum = 1;
}
else
{
tree[id].sum = -1;
tree[id].minsum = -1;
}
return;
}
int mid = (r+l)/2;
build(id*2,l,mid);
build(id*2+1,mid,r);
tree[id].sum = tree[id*2].sum + tree[id*2+1].sum;
tree[id].minsum = min(tree[id*2].minsum,tree[id*2].minsum+tree[id*2+1].minsum);
}
void modify(int index,int id,int l,int r)
{
if(r-l<2)
{
tree[id].sum = tree[id].minsum = -tree[id].sum;
return;
}
int mid = (r+l)/2;
if(index<mid)
modify(index,id*2,l,mid);
else
modify(index,id*2+1,mid,r);
tree[id].sum = tree[id*2].sum + tree[id*2+1].sum;
tree[id].minsum = min(tree[id*2].minsum,tree[id*2].minsum+tree[id*2+1].minsum);
}
int main()
{
int n,k;
int val;
int h = 1;
for(int h=1;h<=10;h++)
{
scanf("%d",&n);
scanf("%s",str);
build(1,0,n);
//cout<<"Test "<<h<<" :"<<endl;
printf("Test %d:\n",h);
//cin>>k;
scanf("%d",&k);
while(k--)
{
cin>>val;
if(!val)
{
if(tree[1].sum == 0 && tree[1].minsum == 0)
{
//cout<<"YES"<<endl;
printf("YES\n");
}
else
{
//cout<<"NO"<<endl;
printf("NO\n");
}
//cout<<tree[1].sum<<"------------"<<tree[1].minsum<<endl;
}
else
{
modify(val-1,1,0,n);
}
}
}
return 0;
}
i have this code that is a Plugin for Unreal Engine 4 is to allow MFI game controllers (Physical Bluetooth Gamepad, Joystick) to be used in my game on iOS devices
the plugin works fine if the game (App) is launched before connecting the controller
the problem is if the game controller is connected before launching the game the game crashes after the splash screen
also disconnecting the controller whilst the game is running closes/crashes the game
any advice is much appreciated
#include "IOSInputInterfacePrivatePCH.h"
#include "IInputInterface.h"
#include "IOSGamepad.h"
/** Beginning of FGCControllerNotificationHandler class */
#if PLATFORM_IOS
#interface FGCControllerNotificationHandler : NSObject
#property FIOSGamepad* device;
+ (id)sharedInstance;
#end
#implementation FGCControllerNotificationHandler
#synthesize device;
- (id)init
{
self = [super init];
return self;
}
+ (id)alloc
{
return [super allocWithZone:NULL];
}
+ (id)allocWithZone:(NSZone *)zone {
return [[self sharedInstance] retain];
}
- (id)copyWithZone:(NSZone *)zone {
return self;
}
- (id)retain {
return self;
}
- (NSUInteger)retainCount {
return NSUIntegerMax; /** denotes an object that cannot be released */
}
- (oneway void)release {
/** never release */
}
- (id)autorelease {
return self;
}
- (void)dealloc {
[super dealloc];
}
+ (FGCControllerNotificationHandler *)sharedInstance
{
static FGCControllerNotificationHandler* instance;
#synchronized(self)
{
if (instance == nil)
{
instance = [[self alloc] init];
}
}
return instance;
}
- (void)registerObservers:(FIOSGamepad *)inDevice
{
self.device = inDevice;
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
/** Assign controller when connected */
[center addObserver:self
selector:#selector(setupControllers)
name:GCControllerDidConnectNotification
object:nil];
/** Do something after controller disconnection */
[center addObserver:self
selector:#selector(cleanControllers)
name:GCControllerDidDisconnectNotification
object:nil];
/** Search for another controller */
[GCController startWirelessControllerDiscoveryWithCompletionHandler:nil];
/** Assign controller id for known controllers */
if ([[GCController controllers] count] > 0)
{
[self setupControllers];
}
}
- (void)setupControllers
{
if(device != nil)
{
self.device->OnControllerConnected();
}
}
- (void)cleanControllers
{
if(device != nil)
{
self.device->OnControllerDisconnected();
}
}
- (int32)getControllerCount
{
return (int32)[[GCController controllers] count];
}
- (TArray<GCController *>)getConnectedControllers
{
TArray<GCController *> availableControllers;
for (GCController* c in [GCController controllers])
{
availableControllers.Add(c);
}
return availableControllers;
}
#end
#endif
/** End of FGCControllerNotificationHandler class */
/** Beginning of FIOSGamepad class */
FIOSGamepad::FIOSGamepad(const TSharedRef<FGenericApplicationMessageHandler>& InMessageHandler) :
MessageHandler(InMessageHandler)
{
#if PLATFORM_IOS
/** In the engine, all controllers map to xbox controllers for consistency */
IOSToXboxControllerMapping[0] = 0; // FaceButtonBottom
IOSToXboxControllerMapping[1] = 1; // FaceButtonRight
IOSToXboxControllerMapping[2] = 2; // FaceButtonLeft
IOSToXboxControllerMapping[3] = 3; // FaceButtonTop
IOSToXboxControllerMapping[4] = 4; // L1
IOSToXboxControllerMapping[5] = 5; // R1
IOSToXboxControllerMapping[6] = 6; // None
IOSToXboxControllerMapping[7] = 7; // None
IOSToXboxControllerMapping[8] = 8; // None
IOSToXboxControllerMapping[9] = 9; // None
IOSToXboxControllerMapping[10] = 10; // L2
IOSToXboxControllerMapping[11] = 11; // R2
IOSToXboxControllerMapping[12] = 12; // Dpad up
IOSToXboxControllerMapping[13] = 13; // Dpad down
IOSToXboxControllerMapping[14] = 14; // Dpad left
IOSToXboxControllerMapping[15] = 15; // Dpad right
IOSToXboxControllerMapping[16] = 16; // Left stick up
IOSToXboxControllerMapping[17] = 17; // Left stick down
IOSToXboxControllerMapping[18] = 18; // Left stick left
IOSToXboxControllerMapping[19] = 19; // Left stick right
IOSToXboxControllerMapping[20] = 20; // Right stick up
IOSToXboxControllerMapping[21] = 21; // Right stick down
IOSToXboxControllerMapping[22] = 22; // Right stick left
IOSToXboxControllerMapping[23] = 23; // Right stick right
Buttons[0] = FGamepadKeyNames::FaceButtonBottom;
Buttons[1] = FGamepadKeyNames::FaceButtonRight;
Buttons[2] = FGamepadKeyNames::FaceButtonLeft;
Buttons[3] = FGamepadKeyNames::FaceButtonTop;
Buttons[4] = FGamepadKeyNames::LeftShoulder;
Buttons[5] = FGamepadKeyNames::RightShoulder;
Buttons[6] = FGamepadKeyNames::SpecialRight;
Buttons[7] = FGamepadKeyNames::SpecialLeft;
Buttons[8] = FGamepadKeyNames::LeftThumb;
Buttons[9] = FGamepadKeyNames::RightThumb;
Buttons[10] = FGamepadKeyNames::LeftTriggerThreshold;
Buttons[11] = FGamepadKeyNames::RightTriggerThreshold;
Buttons[12] = FGamepadKeyNames::DPadUp;
Buttons[13] = FGamepadKeyNames::DPadDown;
Buttons[14] = FGamepadKeyNames::DPadLeft;
Buttons[15] = FGamepadKeyNames::DPadRight;
Buttons[16] = FGamepadKeyNames::LeftStickUp;
Buttons[17] = FGamepadKeyNames::LeftStickDown;
Buttons[18] = FGamepadKeyNames::LeftStickLeft;
Buttons[19] = FGamepadKeyNames::LeftStickRight;
Buttons[20] = FGamepadKeyNames::RightStickUp;
Buttons[21] = FGamepadKeyNames::RightStickDown;
Buttons[22] = FGamepadKeyNames::RightStickLeft;
Buttons[23] = FGamepadKeyNames::RightStickRight;
bNeedsControllerStateUpdate = true;
InitialButtonRepeatDelay = 0.2f;
ButtonRepeatDelay = 0.1f;
/** Initialize ControllerStates */
for (int32 ControllerIndex=0; ControllerIndex < MAX_NUM_IOS_CONTROLLERS; ++ControllerIndex)
{
FControllerState& ControllerState = ControllerStates[ControllerIndex];
FMemory::Memzero(&ControllerState, sizeof(FControllerState));
ControllerState.ControllerId = ControllerIndex;
}
[[FGCControllerNotificationHandler sharedInstance] registerObservers:this];
#endif
}
FIOSGamepad::~FIOSGamepad()
{
}
void FIOSGamepad::Tick(float DeltaTime)
{
}
void FIOSGamepad::SendControllerEvents()
{
#if PLATFORM_IOS
for (int32 ControllerIndex=0; ControllerIndex < MAX_NUM_IOS_CONTROLLERS; ++ControllerIndex)
{
FControllerState& ControllerState = ControllerStates[ControllerIndex];
if (!ControllerState.bIsConnected && bNeedsControllerStateUpdate)
{
ControllerState.bIsConnected = (ControllerIndex < ((int32) [[GCController controllers] count]));
}
if (ControllerState.bIsConnected)
{
bool CurrentStates[MAX_NUM_IOS_CONTROLLER_BUTTONS] = {0};
GCController* Controller = [GCController controllers][ControllerIndex];
if (Controller.extendedGamepad != nil)
{
GCExtendedGamepad* ExGamepad = Controller.extendedGamepad;
/** Check Analog state */
if(ControllerState.LeftXAnalog != ExGamepad.leftThumbstick.xAxis.value)
{
MessageHandler->OnControllerAnalog(FGamepadKeyNames::LeftAnalogX, ControllerState.ControllerId, ExGamepad.leftThumbstick.xAxis.value);
ControllerState.LeftXAnalog = ExGamepad.leftThumbstick.xAxis.value;
}
if(ControllerState.LeftYAnalog != ExGamepad.leftThumbstick.yAxis.value)
{
MessageHandler->OnControllerAnalog(FGamepadKeyNames::LeftAnalogY, ControllerState.ControllerId, ExGamepad.leftThumbstick.yAxis.value);
ControllerState.LeftYAnalog = ExGamepad.leftThumbstick.yAxis.value;
}
if(ControllerState.RightXAnalog != ExGamepad.rightThumbstick.xAxis.value)
{
MessageHandler->OnControllerAnalog(FGamepadKeyNames::RightAnalogX, ControllerState.ControllerId, ExGamepad.rightThumbstick.xAxis.value);
ControllerState.RightXAnalog = ExGamepad.rightThumbstick.xAxis.value;
}
if(ControllerState.RightYAnalog != ExGamepad.rightThumbstick.yAxis.value)
{
MessageHandler->OnControllerAnalog(FGamepadKeyNames::RightAnalogY, ControllerState.ControllerId, ExGamepad.rightThumbstick.yAxis.value);
ControllerState.RightYAnalog = ExGamepad.rightThumbstick.yAxis.value;
}
if(ControllerState.LeftTriggerAnalog != ExGamepad.leftTrigger.value)
{
MessageHandler->OnControllerAnalog(FGamepadKeyNames::LeftTriggerAnalog, ControllerState.ControllerId, ExGamepad.leftTrigger.value);
ControllerState.LeftTriggerAnalog = ExGamepad.leftTrigger.value;
}
if(ControllerState.RightTriggerAnalog != ExGamepad.rightTrigger.value)
{
MessageHandler->OnControllerAnalog(FGamepadKeyNames::RightTriggerAnalog, ControllerState.ControllerId, ExGamepad.rightTrigger.value);
ControllerState.RightTriggerAnalog = ExGamepad.rightTrigger.value;
}
/** Get the current state of all buttons */
CurrentStates[IOSToXboxControllerMapping[0]] = ExGamepad.buttonA.pressed;
CurrentStates[IOSToXboxControllerMapping[1]] = ExGamepad.buttonB.pressed;
CurrentStates[IOSToXboxControllerMapping[2]] = ExGamepad.buttonX.pressed;
CurrentStates[IOSToXboxControllerMapping[3]] = ExGamepad.buttonY.pressed;
CurrentStates[IOSToXboxControllerMapping[4]] = ExGamepad.leftShoulder.pressed;
CurrentStates[IOSToXboxControllerMapping[5]] = ExGamepad.rightShoulder.pressed;
CurrentStates[IOSToXboxControllerMapping[6]] = false;
CurrentStates[IOSToXboxControllerMapping[7]] = false;
CurrentStates[IOSToXboxControllerMapping[8]] = false;
CurrentStates[IOSToXboxControllerMapping[9]] = false;
CurrentStates[IOSToXboxControllerMapping[10]] = ExGamepad.leftTrigger.value > IOS_TRIGGER_THRESHOLD;
CurrentStates[IOSToXboxControllerMapping[11]] = ExGamepad.rightTrigger.value > IOS_TRIGGER_THRESHOLD;
CurrentStates[IOSToXboxControllerMapping[12]] = ExGamepad.dpad.up.pressed;
CurrentStates[IOSToXboxControllerMapping[13]] = ExGamepad.dpad.down.pressed;
CurrentStates[IOSToXboxControllerMapping[14]] = ExGamepad.dpad.left.pressed;
CurrentStates[IOSToXboxControllerMapping[15]] = ExGamepad.dpad.right.pressed;
CurrentStates[IOSToXboxControllerMapping[16]] = ExGamepad.leftThumbstick.up;
CurrentStates[IOSToXboxControllerMapping[17]] = ExGamepad.leftThumbstick.down;
CurrentStates[IOSToXboxControllerMapping[18]] = ExGamepad.leftThumbstick.left;
CurrentStates[IOSToXboxControllerMapping[19]] = ExGamepad.leftThumbstick.right;
CurrentStates[IOSToXboxControllerMapping[20]] = ExGamepad.rightThumbstick.up;
CurrentStates[IOSToXboxControllerMapping[21]] = ExGamepad.rightThumbstick.down;
CurrentStates[IOSToXboxControllerMapping[22]] = ExGamepad.rightThumbstick.left;
CurrentStates[IOSToXboxControllerMapping[23]] = ExGamepad.rightThumbstick.right;
}
else if (Controller.gamepad != nil)
{
GCGamepad* Gamepad = Controller.gamepad;
/** Get the current state of all buttons */
CurrentStates[IOSToXboxControllerMapping[0]] = Gamepad.buttonA.pressed;
CurrentStates[IOSToXboxControllerMapping[1]] = Gamepad.buttonB.pressed;
CurrentStates[IOSToXboxControllerMapping[2]] = Gamepad.buttonX.pressed;
CurrentStates[IOSToXboxControllerMapping[3]] = Gamepad.buttonY.pressed;
CurrentStates[IOSToXboxControllerMapping[4]] = Gamepad.leftShoulder.pressed;
CurrentStates[IOSToXboxControllerMapping[5]] = Gamepad.rightShoulder.pressed;
CurrentStates[IOSToXboxControllerMapping[6]] = false;
CurrentStates[IOSToXboxControllerMapping[7]] = false;
CurrentStates[IOSToXboxControllerMapping[8]] = false;
CurrentStates[IOSToXboxControllerMapping[9]] = false;
CurrentStates[IOSToXboxControllerMapping[10]] = false;
CurrentStates[IOSToXboxControllerMapping[11]] = false;
CurrentStates[IOSToXboxControllerMapping[12]] = Gamepad.dpad.up.pressed;
CurrentStates[IOSToXboxControllerMapping[13]] = Gamepad.dpad.down.pressed;
CurrentStates[IOSToXboxControllerMapping[14]] = Gamepad.dpad.left.pressed;
CurrentStates[IOSToXboxControllerMapping[15]] = Gamepad.dpad.right.pressed;
CurrentStates[IOSToXboxControllerMapping[16]] = false;
CurrentStates[IOSToXboxControllerMapping[17]] = false;
CurrentStates[IOSToXboxControllerMapping[18]] = false;
CurrentStates[IOSToXboxControllerMapping[19]] = false;
CurrentStates[IOSToXboxControllerMapping[20]] = false;
CurrentStates[IOSToXboxControllerMapping[21]] = false;
CurrentStates[IOSToXboxControllerMapping[22]] = false;
CurrentStates[IOSToXboxControllerMapping[23]] = false;
}
const double CurrentTime = FPlatformTime::Seconds();
/** For each button check against the previous state and send the correct message if any */
for (int32 ButtonIndex = 0; ButtonIndex < MAX_NUM_IOS_CONTROLLER_BUTTONS; ++ButtonIndex)
{
if(CurrentStates[ButtonIndex] != ControllerState.ButtonStates[ButtonIndex])
{
if(CurrentStates[ButtonIndex])
{
MessageHandler->OnControllerButtonPressed(Buttons[ButtonIndex], ControllerState.ControllerId, false);
}
else
{
MessageHandler->OnControllerButtonReleased(Buttons[ButtonIndex], ControllerState.ControllerId, false);
}
if(CurrentStates[ButtonIndex] == true)
{
/** this button was pressed - set the button's NextRepeatTime to the InitialButtonRepeatDelay */
ControllerState.NextRepeatTime[ButtonIndex] = CurrentTime + InitialButtonRepeatDelay;
}
}
else if(CurrentStates[ButtonIndex] == true && ControllerState.NextRepeatTime[ButtonIndex] <= CurrentTime)
{
MessageHandler->OnControllerButtonPressed(Buttons[ButtonIndex], ControllerState.ControllerId, true);
/** set the button's NextRepeatTime to the ButtonRepeatDelay */
ControllerState.NextRepeatTime[ButtonIndex] = CurrentTime + ButtonRepeatDelay;
}
/** Update the state for next time */
ControllerState.ButtonStates[ButtonIndex] = CurrentStates[ButtonIndex];
}
}
}
bNeedsControllerStateUpdate = false;
#endif
}
void FIOSGamepad::SetMessageHandler(const TSharedRef<FGenericApplicationMessageHandler>&InMessageHandler)
{
MessageHandler = InMessageHandler;
}
bool FIOSGamepad::Exec(UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar)
{
return false;
}
void FIOSGamepad::SetChannelValue (int32 ControllerId, FForceFeedbackChannelType ChannelType, float Value)
{
}
void FIOSGamepad::SetChannelValues (int32 ControllerId, const FForceFeedbackValues &values)
{
}
void FIOSGamepad::OnControllerConnected ()
{
for(int32 ControllerIndex=0; ControllerIndex < FMath::Min<int32>(MAX_NUM_IOS_CONTROLLERS, [[GCController controllers] count]); ++ControllerIndex)
{
[GCController controllers][ControllerIndex].playerIndex = (GCControllerPlayerIndex)ControllerIndex;
}
this->bNeedsControllerStateUpdate = true;
}
void FIOSGamepad::OnControllerDisconnected ()
{
this->bNeedsControllerStateUpdate = true;
}
/** End of FIOSGamepad class */
I'm using the following function in order to get all the keys and values of the preferences.plist file located in: /private/var/preferences/SystemConfiguration/preferences.plist
- (void)FindKeysAndValuesInPlist:(id)object forKeyNamed:(NSString *)keyName{
if ([object isKindOfClass:[NSDictionary class]])
{
NSLog(#"%#",keyName);
[object enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
[self FindKeysAndValuesInPlist:value forKeyNamed:key];
}];
}
else if ([object isKindOfClass:[NSArray class]])
{
[object enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[self FindKeysAndValuesInPlist:obj forKeyNamed:nil];
}];
}
else
{
NSLog(#"%#.%#", keyName, object);
}
}
An example of the content of preferences.plist:
{
CurrentSet = "/Sets/3B9E7BEB-5558-4497-803B-21B03E6A46C0";
NetworkServices = {
"014226AB-75B7-41CF-9B96-48E82FD6A395" = {
Interface = {
DeviceName = ip4;
Hardware = "com.apple.CommCenter";
Type = "com.apple.CommCenter";
UserDefinedName = "com.apple.CommCenter (ip4)";
};
PrimaryRank = Never;
UserDefinedName = "com.apple.CommCenter (ip4)";
"com.apple.CommCenter" = {
AllowNetworkAccess = 0;
Available = 1;
Version = 11;
};
};
"1C01B561-1A55-4E3B-82FC-CDFF5024F0D2" = {
Interface = {
DeviceName = ip1;
Hardware = "com.apple.CommCenter";
Type = "com.apple.CommCenter";
UserDefinedName = "com.apple.CommCenter (ip1)";
};
UserDefinedName = "com.apple.CommCenter (ip1)";
"com.apple.CommCenter" = {
AllowNetworkAccess = 1;
Available = 1;
SettingsHaveBeenAlteredByPreferences = 1;
Setup = {
apn = "";
password = "";
signature = <7ecb277c ad546563 3ac057fb db40aeaa 939f8c0e e7ae68c2 6e0ff602 77d3868d 18a63059 6c83f66d 46b8af57 d1bf83d0 2655ced6 57d773f4 5c7e733e 923aaa07 39165357 a4ecf270 130276f0 59c7470e 0b61a631 dff04fd1 0bc80cb4 a0dc0a03 96a8ebf0 74c24cdb 84c38239 9f6f7f05 ee032982 8ed1b72d b531405b 09e35f5b>;
"type-mask" = 0;
username = "";
};
Version = 11;
};
};
The problem is that I'm trying to create this kind of output format: MAINKEY.SUBKEY.VALUE
For example:
NetworkServices = {
"014226AB-75B7-41CF-9B96-48E82FD6A395" = {
Interface = {
DeviceName = ip4;
Hardware = "com.apple.CommCenter";
Type = "com.apple.CommCenter";
UserDefinedName = "com.apple.CommCenter (ip4)";
};
Would be: NetworkServices.014226AB-75B7-41CF-9B96-48E82FD6A395.Interface.Hardware.ip4
Iterate over the keys in a dictionary. When the value for a key is another dictionary, push the key onto a stack and recurse on the dictionary value. When the value is a string or number, then concatenate the keys in the stack and print the key path and value.
Code:
+ (void)printDict:(NSDictionary *)dict keyStack:(NSArray *)keys
{
if (keys == nil) {
keys = [NSArray array];
}
for (id key in dict) {
id value = dict[key];
if ([value respondsToSelector:#selector(objectForKey:)]) {
[self printDict:value keyStack:[keys arrayByAddingObject:key]];
} else {
NSLog(#"%# = %#", [[keys arrayByAddingObject:key] componentsJoinedByString:#"."], value);
}
}
}