Integer not incrementing because of an if statement

I have an Objective-C app here - and I am wishing to alter a variable (integer) each time the app runs. My code below will work, but when the integer reaches the number specified in the if statement, it no longer increments as instructed.
- (void)awakeFromNib
[NSUserDefaults init];
int numberOfTimes;
numberOfTimes = [[NSUserDefaults standardUserDefaults] integerForKey:@"used"];
++numberOfTimes;
[[NSUserDefaults standardUserDefaults] setInteger:numberOfTimes forKey:@"used"];
NSLog (@"%d", [[NSUserDefaults standardUserDefaults] integerForKey:@"used"]);
if ([[NSUserDefaults standardUserDefaults] integerForKey:@"used"]<15){
Can anyone pinpoint or think of a reason why this would be happening?
Cheers,
Ricky.

Hi Ricky--
I can't be sure what's happening with your code. But I can suggest an alternate way to do it that will increment forever.
The first part, in the initializer, just sets up sensible defaults when you app has never run before. Then the second part, during the awake from nib, actually reads the saved defaults, increments the integer, then saves it back.
+ (void)initialize
// Get a dictionary for my default values:
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
// initially let it be 0:
[defaultValues setObject:[NSNumber numberWithInt:0] forKey:@"used"];
// Register my dictionary with the defaults system:
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
NSLog(@"Registered defaults: %@", defaultValues);
- (void)awakeFromNib
// get the user defaults for this app:
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
// Get the integer value:
int launchCount = [userDefaults integerForKey:@"used"];
NSLog(@"Pre-increment value: %i", launchCount);
launchCount++;
if (launchCount <= 5 )
NSLog(@"Post-increment value: %i", launchCount);
else
NSLog(@"Post-increment is over 5: %i", launchCount);
// Save it back to the defaults, so it'll show up again next launch:
[userDefaults setInteger:launchCount forKey:@"used"];
The values set in the initialization would be used if there's nothing stored on disk yet for the app. But if the app has already run once, when you get the user defaults in the awake from nib method, the defaults system is smart enough to know that the application has preferences stored on disk, so it gives those to you instead.
I also like to use more variables to store values. I probably could have gotten by with nesting more methods, but that confuses me. And I think it might provide a key to why your integer stops being incremented, but I'm not sure I can pinpoint why.
charlie

Similar Messages

  • Error message states iTunes could not connect because paring record is missing, how do I fix?

    Error message states iTunes could not connect because paring record is message is missing, how do I fix?

    Sometimes rebooting your PC can clear this error message.  You might also want to try plugging the iPod into a different USB port as well.
    Others have been able to fix it by unplugging their iPod from their PC, signing out their Apple ID on their iPod Touch, signing back in and reconnecting it.
    B-rock

  • AirPort Utility 5.6 for Mac OS X Lion The installer will not install because it states the OS is not supported. I have the latest

    AirPort Utility 5.6 for Mac OS X Lion The installer will not install because it states the OS is not supported. I have the latest

    Part of your message was not included. Can you re-post with details again please?

  • Annoying 'Could not use the history eraser because the current canvas size does not match that of the history state' message

    Does anyone know if it is possible to get rid of the message 'Could not use the history eraser because the current canvas size does not match that of the history state'?. It comes up if I hit the alt/option key while I have the eraser selected. Something I do by accident all the time.

    The way you've described it, one gets the distinct impression you do not have a clue as to what the history brush does and how to use it.
    You need to read up on it.  Read the Help files and google for tutorials.
    First you need to create an image (with actual pixels in it), edit it as desired, then make a snapshot of the edited image, then target the snapshot with the history brush tool, then go back in the History panel to the step before your edits and selectively paint your edits in with the History Brush.

  • Error occurred in deployment step 'Add Solution': Operation is not valid due to the current state of the object

    hi,
      when i was trying to deploy a SP  solution from my vs 2012 solution. this error  is displayed.
    i tried many things like
    1) get the wsp and apply power shell cmds to add and deploy, here also it failed:
    Add-SPSolution -LiteralPath d:\mywsp.wsp
    Install-SPSolution mywsp.wsp -GacDeployment -AllWebApplications -Local
    2) restart the timer services and  do  iisreset and  reboot the server. etc .as mentioned in one of the  the below  blogs:
    http://sharepoint1on1.blogspot.in/2014/04/sharepoint-error-occurred-in-deployment.html
    http://suehernandez.wordpress.com/2011/03/31/error-occurred-in-deployment-step-activate-features-operation-is-not-valid-due-to-the-current-state-of-the-object/
    http://www.dotnetsharepoint.com/2014/04/error-occurred-in-deployment-step-add.html
    http://social.msdn.microsoft.com/Forums/en-US/63adde23-03cf-4b65-923e-1219da94a780/error-occurred-in-deployment-step-add-solution-operation-is-not-valid-due-to-the-current-state-of?forum=sharepointdevelopmentprevious
    http://www.shakirmajeed.com/error-occurred-in-deployment-step-activate-features-operation-is-not-valid-due-to-the-current-state-of-the-object/
    but even after doing all these steps, the  error still persists!. and am not deploying into a remote server, the dev env is in a VM, where sp 2013, vs 2012, sql 2012  are installed.
    just wanna share one  note:   there is a isue in my search admin component. index was reset due to some reason. and from that time onwards my search full/incremental crawls were not working!
    will this cause an issue in my wsp deployment ? i hope  it wont, still  asking...
    can anyone help me how to resolve this error.because this is a  show stopper for me for the last few days!
    help is highly appreciated!

    This issue cause because of feature activation failure while WSP deployment.
    when you create a WSP using visual studio, it creates WSP package with default deployment configuration settings.
    Please restrict feature activation configuration, this will help you to troubleshoot this issue.
    - Click on Project in WSP and press F4, it will open "Project Properties"
    - set "Active deployment Configuration" - as "No Activation"
    - you can activate this features in required sequence after deployment using Activate-SPFeature
    If my contribution helps you, please click Mark As Answer on that post and Vote as Helpful
    Thanks, ShankarSingh(MCP)

  • Reporting Service Integration mode and Key not valid for use in specified state

    I had to uninstall SharePoint Foundation 2013 and reinstall it.
    What I have done:
    I uninstalled SharePoint and after that I removed all databases.
    I reinstalled SharePoint Foundation 2013 and it completed without errors.
    Everything else is working, except SSRS in Sharepoint Integrated Mode.
    If I check Central Administration - Manage services on server, I can found out that SQL Server Reporting Service Service is
    "Started". But if I try to create new service application (SQL Server Reporting Services Service Application), it gives me an error message:
    "Key not valid for use in specified state. (Exception from HRESULT: 0x8009000B)"
    I uninstalled SSRS in Sharepoint Integrated Mode and I reinstalled it but problems exists.
    It seems that "Encryption Keys" cause this problem.
    https://support.microsoft.com/kb/955757
    https://msdn.microsoft.com/en-us/library/ms156010%28v=sql.110%29.aspx
    I tried to Re-create Encryption Keys and Delete keys, but its not working either. It gives me only error message that:
    "Unable to locate the Reporting Server Windows service for instance MSSQLSERVER."
    I don't have any reporting server databases, because I removed all
    databases when I uninstalled SharePoint. Also I don't have Encryption
    Keys backups.
    I have found several similar question but no answer, example here:
    https://social.technet.microsoft.com/Forums/ie/en-US/df02dc05-5ce8-499d-9ba3-ab392a5fc3af/sharepoint-2013-ssrs-application-error-key-not-valid-for-use-in-specified-state-exception?forum=sharepointdevelopment
    Any ideas how I can fix this problem?

    Hi,
    From the Reporting Server Configuration Manager you have to restore the encryption key.
    Please try to delete databases(reportserver & reportservertempdb) and delete the reportserver and reports site on IIS. Then you have to start over the configuration again.
    If the issue still exists, Please check ULS log to see if anything unexpected occurred.
    For SharePoint 2013, by default, ULS log locates in
    "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\LOGS"
    More information about SQL Reporting services Installation with SharePoint 2013 for your reference:
    http://expertsharepoint.blogspot.de/2014/03/sql-reporting-services-installation.html
    Best Regards,
    Dennis Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • The backup was not performed because an error occurred while copying files

    One Time Capsule, Two MacBook's, OS10.6.6
    One MacBook can backup no problem, The other cannot backup says: the backup was not performed because an error occurred while copying files to the backup disk.
    Using a Time Machine Buddy widget gives:
    Starting standard backup
    Attempting to mount network destination using URL: afp://Rachel%[email protected]/Data
    Mounted network destination using URL: afp://Rachel%[email protected]/Data
    QUICKCHECK ONLY; FILESYSTEM CLEAN
    Disk image /Volumes/Data/Rachel Feuchtwang’s MacBook.sparsebundle mounted at: /Volumes/Time Machine Backups
    Backing up to: /Volumes/Time Machine Backups/Backups.backupdb
    No pre-backup thinning needed: 4.70 GB requested (including padding), 721.52 GB available
    Indexing a file failed. Returned 200 for: /Applications/Dashboard.app, /Volumes/Time Machine Backups/Backups.backupdb/Rachel Feuchtwang’s MacBook/2011-01-12-115852.inProgress/F82EB140-616F-4213-9B4A-072C2C98B556/MAC/A pplications/Dashboard.app
    Aborting backup because indexing a file failed.
    Stopping backup.
    Copied 5 files (84 bytes) from volume MAC.
    Copy stage failed with error:11
    Backup failed with error: 11
    Ejected Time Machine disk image.
    Ejected Time Machine network volume.
    Who would be so kind to point me in the direction to make thsi work again?
    Thanks! Hugo

    This could very well have to do with ACLs.
    I bumped into the same problem:
    5/8/11 10:43:22 PM          com.apple.backupd[7126]          Error: (-41) SrcErr:NO Copying /Users/SA/Public/Drop Box/HandBrake.app/Contents/Frameworks/Sparkle.framework/Versions/A/ Resources/de.lproj/SUAutomaticUpdateAlert.nib/classes.nib to /Volumes/Local Backup/Backups.backupdb/Server/2011-05-08-221524.inProgress/88ACE716-0660-44C8- A128-CF01046FC2F8/Macintosh HD/Users/SA/Public/Drop Box/HandBrake.app/Contents/Frameworks/Sparkle.framework/Versions/A/ Resources/de.lproj/SUAutomaticUpdateAlert.nib
    Using DD or CCC is no option for me, I don't want downtime and I want incremental backups. So I started to investigate.
    I repartitioned my external Time Machine drive, did the backup again. It didn't work. Then I blocked the culprit file mentioned in the logs from being backed up with TM. That helped, only to find that a bit later it found another file with issues.
    So i looked at the files an found they had ACLs on them that somehow prevented them from being copied.
    SOLUTION:
    remove the ACL from the file.
    If you want to remove all ACLs in a directory, use Terminal and navigate to that directory. Then issue this command:
    sudo echo | sudo chmod -R -E ./*
    If you would like to remove ACLs from a single file or package (e.g. an application), issue this:
    sudo echo | sudo chmod -R -E <nameoffile>
    You might have to this several times since there might be multiple files affected. Unlike previous solutions, this one does not require you to delete the file.
    I got the command to remove ACLs from http://osxadmin.blogspot.com/2008/01/chmod-acl-removal.html

  • "Key not valid for use in specified state" after IIS Reset?

    I have had a ton of issues with the System.Security.Cryptography.CryptographicException: Key not valid for use in
    specified state. error. This seems to only occur now when IIS is reset and I try to resume my browsing session. So I am logged into the application, I reset IIS on the server, refresh the page and see the error.
    I am building an application in .NET 4.0 MVC with a Secure Token Service that is using WIF 4.0. Everything works as expected, except this case. I even tried to use a custom error page, but the error is happening there as well. Because of that, I can't get the
    custom page to show either. One thing I noticed is that if I switch my IIS APP Pool user back to Network Service account it doesn't throw the error any more. We have some restrictions (mostly network related) in the application that we need to use an account
    in our AD for the app pool sections
    Anybody have any experience with this issue?

    Hi Shennessy,
    In my opinion, this thread is related to ASP.NET forum. So please post thread on that forum for more effective response. Thank you for understanding. Please refer to the following link.
    http://forums.asp.net/.
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for use in specified state

    we have developed packages to do the followings
    Extract data from DB2 Source and put it in MS Sql Server 2008 database (Lets Say DatabaseA).From MS Sql Server 2008 (DatabaseA)
    we will process the data and place it in another database MS Sql Server 2008 (DatabaseB)
    We have created packages in BIDS..We created datasource connection in Datasource folder in BIDS..Which has DB2 Connection and both Ms Sql Server connection (Windows authentication-Let
    say its pointing to the server -ServerA which has DatabaseA and DatabaseB).The datasource connections will be used in packages during development.
    For deployment we have created Package Configuration which will have both DB2 Connection and MS SqlServer connection in the config
    We deployed the packages in different MS SqlServer by changing the connectionstring in the config for DB2 and MS SqlServer...
    While runing the package we are getting the following error message
    Code: 0xC0016016     Source:       Description: Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for
    use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the correct key is available.
    ilikemicrosoft

    Hi Surendiran,
    This is because the package has been created by somebody else and the package is being deployed under sombody else's account. e.g. If you are the creator then the package is encryption set according to your account and the package setup in SQL server is
    under a different user account.
    This happens because the package protection level is set to EncryptSensitiveWithUserKey which encrypts
    sensitive information using creator's account name.
    As a solution:
    Either you have to set up the package in SQL server under your account (which some infrastructures do not allow).
    OR
    Set the package property Protection Level to "DontSaveSensitive" and add a configuration file
    to the package and set the initial values for all the variables and all the connection manager in that configuration file (which might be tedious of-course).
    OR
    The third options (which I like do) is to open the package file and delete the password encryption entries from the package. Do note that this is not supported by designer and every time you make changes to the connection managers these encryption entries come
    back.
    Hope this helps. 
    Please mark the post as answered if it answers your question

  • SQL Server Mgt Studio 2008 installation problem - Key not valid for use in specified state

    I'm setting up SQL Server Management Studio 2008 on my laptop.  It installed fine, but failed to import a regsrver file exported from another machine. This appears to have been due to the fact that I exported the file with usernames and passwords, although I must admit that's pretty darned inconvenient if it can't be done. 
    Nevertheless, I exported the file again without usernames and passwords, but the new install now won't let me even see servers, let alone import any new ones.
    When I start Studio, it gives me the "Key not valid for use in specified state" error.  When I 'continue', I'm delivered to a screen with the 'registered servers' pane crippled.  It has no contents at all and no ability to add, select, import, export.  Nothing there.
    How do I rectify this?
    The installation is on Windows 7 Home Premium.
    Thanks for any suggestions.

    Hi Don,
    Since this issue was still not resolved even after you reinstall SQL Server 2008, I think that this issue is probably related to some corrupted files or registry keys. Please refer to the following steps to see if you can resolve this issue:
    1. Close your SSMS;
    2. Go to the folder %appdata%\Microsoft\Microsoft SQL Server\100\Tools\ and check if there is a Shell folder, if so, rename it to Shell-Copy;
    3. Re-open your SSMS to see if the error persists.
    Everytime SQL Server 2008 Management Studio starts, it will read information from this folder to retrieve and recover some data. If the information does not exists, it will recreate new ones. Please check if this helps.
    Best regards,
    Charles Wang
    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    To add to Don's comment, if you are using a different account (for example, an SA account) to run SQL Server management studio then make sure to change the user profile name when you browse to "%appdata%\Microsoft\Microsoft SQL Server\100\Tools\".
    I know many of us developers have multiple accounts and I usually have my SA account have logon privileges on databases not my regular AD Account.
    Other than that, the reason why this fails is because MS encrypted the regsrvr file on the source computer using the source computer's ID and is therefore unable to decrypt the file on the destination computer. To me that just doesn't make sense since the
    whole idea of Export and import was to move this information across computers! And that's why this works when you import without username and passwords - no more encryption/decryption. Since we use integrated windows logon (trusted_connection=true) it works
    great. For the few servers that we had SQL Logons I had to manually type them in and save. But all in all, pretty painless.

  • Install error- key not valid for use in specified state

    after downloading and starting installation I keep getting the error "key not valid for use in specified state"
    I am using an administrator account and have selected to run the install application as an administrator.
    What is causing this?

    Generally this error happens because of an encrypted folder or insufficient permissions on that folder: http://support.microsoft.com/kb/834484 (MS Explanation)
    Adobe has a page here: Error 1603: A fatal error occurred during installation

  • Event 701 - The Application Impact Telemetry (AIT) Agent is not running because AIT is disabled.

    In a survey of several Windows 7 systems, in the Application-Experience Program-Telemetry log, I found daily instances of Information Event 701 "The Application Impact Telemetry (AIT) Agent is not running because AIT is disabled".  The trigger
    for this event is execution of the built-in scheduled task to run Aitagent.exe daily at 02:30.
    The message "AIT is disabled" is puzzling to me. 
    I checked participation in the Customer Experience Improvement Program (CEIP) on the idea that a setting to disable participation could translate into "AIT is disabled", but CEIP is set to Yes (participate).
    I checked Windows Error Reporting settings - they are set to "Automatically check for solutions and send additional report data, if needed"
    I checked the REG_DWORD value AITEnable in HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\AIT is set to 0x1, which should indicate that AIT is enabled.
    I would appreciate if anyone can explain where/how AIT is disabled.
    Thanks

    Arthur Xie-
    Thank you for suggesting installing the
    Microsoft Application Compatibility Toolkit 5.6 (ACT).  This is quite an enterprise-level program (the Step-by-Step guide says "We
    recommend that you collect your data from approximately 10,000
    computers")! 
    Anyway, installing the ACT and sending an empty data set to Microsoft worked, but did not eliminate Event 701 when the scheduled task to run AitAgent.exe executed
    (as scheduled or manually) or when AitAgent.exe was run from an Administrator command prompt.
    Since the scheduled task to run AitAgent.exe is part of a out-of-box installation of Windows 7, and its description states "Aggregates and uploads Application Telemetry
    information if opted-in to the Microsoft Customer Experience Improvement Program", it would seem that it would run without error, at least when participation in the CEIP is enabled.

  • - 0 fatal error(s), 3 error(s)     ----------- Payload: Adobe Photoshop Lightroom 5 5.6.0.0 Adobe_Lightroom_x64.msi_5.6 -----------  ERROR: Key not valid for use in specified state.    ERROR: Install MSI payload failed with error: 1603 - Fatal error durin

    I keep getting this error code when trying to download         
    - 0 fatal error(s), 3 error(s) ----------- Payload: Adobe Photoshop Lightroom 5 5.6.0.0 Adobe_Lightroom_x64.msi_5.6 ----------- ERROR: Key not valid for use in specified state. ERROR: Install MSI payload failed with error: 1603 - Fatal error during installation. MSI Error message: Key not valid for use in specified state. ERROR: Third party payload installer Adobe_Lightroom_x64.msi failed with exit code: 1603

    Generally this error happens because of an encrypted folder or insufficient permissions on that folder: http://support.microsoft.com/kb/834484 (MS Explanation)
    Adobe has a page here: Error 1603: A fatal error occurred during installation

  • It is not possible to reset to factory State

    Ciao
    My pc has this problem: "it is not possible to reset to factory State"
    Noteboock  HP Pavilion dv6-6c65el
    OS: Windows 7 Home Premium 64-bit SP1
    CPU Intel Core i5-2450M CPU @ 2.50\3.10GHz hd3000 integrata
    Graphics Radeon HD 7690M XT 2Gb GDDR5
    BIOS Brand Hewlett-Packard
    Version F.12 Date 10/26/2011
    Hard disk (C) OS+(D) Recovery+(E) HpTools. 
    After performing "reset factory state" (with HP Recovery Manager) I noticed the malfunction IE9 32bit.
    Moreover, the absence of other software preinstalled (missing: Hp Hp setup-documentation-IE9 64bit).
    When I tried a new reset, HP Recovery Manager to the voice system recovery (factory state) tells me:
    (disabled: to restore the system, use recovery media)
    Using Recovery DVD (in excellent condition),you  receive the following error message:
    "windows as encountered a problem comunicating with a device connected to your computer-This errorcan be cause by umpluggin a
    removable storage device such as an exsternal usb drive while the device is in use,or by faulty hardware such as hard drive or cd-rom drive
    that is failing make sure any removable storage is properly connected and then restart your pc" Status:0xc00000c9 Info: an unespected I\O error as occurred"
    The same happens with the F11 key during startup. Reset error.
    The System Restore Microsoft does not resolve.
    In Windows everything else seems to work and the hardware of the notebook has no problems.
    The original dvd player has been replaced with a compatible; reads all the disks supported.
    Only install MSE (I use only portable software).
    There are no viruses or other malaware.
    I performed procedures in hp support but nothing has changed.
    You can find a solution?
    Ciao e grazie
    Lecce2
    This question was solved.
    View Solution.

    I have no more 'answer because my computer had crashed complete.
    I apologize.
    Order the media why?
    If discs created the first time the PC will not work. I suppose that does not solve the problem discs hp (I also read about a problem like mine. This problem has not been resolved with the media bought by HP).
    I shot weeks the web and I finally found the appropriate procedure.
    I made several attempts to solve the problem. But now I have succeeded.
    1- Show Hidden Files \ protected
    2- Enter with a program (es: file commander) in recovery partition and copy the file or files base.wim. My is about 18 Gb, 1 file.
    3- We need a second PC and dvd
    4- Follow a procedure described by internauta 37.
    Search "Ripristinare portatile HP senza DVD e se l'HP Recovery Manager non funziona Internauta37"
    E 'was for me a little complicated but in the end I have my hp to the state of factory and everything works perfectly.
    Thank you all

  • ACE show serverfarm - failure counter does not incremented on Probe-Failure event

    Hi,
    Despite of probe-failure the failure counter is not incremented. Is there any correlation between the configured probe and the failure counter?
    (Custom script probe is used for this serverfarm)
    # sh serverfarm xxxxxSt
    serverfarm     : xxxxxSt, type: HOST
    total rservers : 2
                                                    ----------connections-----------
           real                  weight state        current    total      failures
       ---+---------------------+------+------------+----------+----------+---------
       rserver: xxxxx6
           10.222.0.90:8000      8      OPERATIONAL  13         157        0
       rserver: xxxxx7
           10.222.0.92:8000      8      PROBE-FAILED 0          0          0
    Thanks,
    Attila

    Hi Attila,
    The Connection Failure counter under show serverfarm is for Loadbalanced Connections which are failing.
    If Probes are failing, this counter will not increment.
    The Connection failure counter can increment for various reasons some of them are,
    - Server not responding to the SYN packet sent by ACE for Loadbalanced connection
    - Server sending Reset to the SYN packet sent by ACE for Loadbalanced connection
    To check on stats for Probe, you can run "show probe detail" command.
    Hope this helps,
    Best Regards,
    Rahul

Maybe you are looking for