Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7906571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:02:33+00:00 2026-06-03T11:02:33+00:00

I have this method to save a mutable array named myWallet that contains instances

  • 0

I have this method to save a mutable array named myWallet that contains instances of the Class Card.

- (void)saveMyWallet
{

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [defaults setObject:[NSKeyedArchiver archivedDataWithRootObject:self.myWallet] forKey:@"myWalletArray"];

    [defaults synchronize];
}

The Card Class that I have has three instance variables: name, pin, and points. So far, saving new instances of the Card in UserDefaults is ok. I would just like to know some suggestions on how can I overwrite the value of points because as I proceed in the computation of points, I want to update it.

Here is my Card Class

Card.h

#import <Foundation/Foundation.h>

@interface Card : NSObject <NSCoding>

    @property (nonatomic, strong) NSString *name;
    @property (nonatomic, strong) NSString *pin;
    @property (nonatomic, strong) NSNumber *points;
    @property (nonatomic, strong) NSMutableArray *pointsToDeduct;


- (double) subtractPoints: (double) requiredPoints;
- (void) encodeWithCoder:(NSCoder *)coder;
- (id) initWithCoder: (NSCoder *)coder;
@end

Card.m

#import "Card.h"

@implementation Card 

@synthesize name = _name;
@synthesize pin = _pin;
@synthesize points = _points;
@synthesize pointsToDeduct = _pointsToDeduct;

- (id)initWithCoder:(NSCoder *)coder 
{    
    self = [[Card alloc] init];
    if(self != nil) {
        self.name = [coder decodeObjectForKey:@"name"];
        self.pin = [coder decodeObjectForKey:@"pin"];
        self.points = [coder decodeObjectForKey:@"points"];

    }

    return self;
}

- (void)encodeWithCoder:(NSCoder *)coder 
{
    [coder encodeObject:self.name forKey:@"name"];
    [coder encodeObject:self.pin  forKey:@"pin"];
    [coder encodeObject:self.points forKey:@"points"];

}

- (double) subtractPoints:(double) requiredPoints
{

    double latestPoints;

    latestPoints = ([self.points doubleValue] - requiredPoints);

    return latestPoints;
}

@end

And lastly, here is the delegate method by which the new value of the points (named resultingPoints) should come from.

- (void)perksDetailsViewController:(PerksDetailsViewController *)sender didPassRequiredPoints:(NSNumber *)requiredPoints withCard:(Card *)selectedCard 
{

    double perksPoints = [requiredPoints doubleValue];

    self.resultingPoints = [NSNumber numberWithDouble:[selectedCard subtractPoints:perksPoints] ];

    NSLog(@"points remaining %@", self.resultingPoints); 
}

Bombard me with suggestions 🙂 Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:02:35+00:00Added an answer on June 3, 2026 at 11:02 am

    From what I see, you actually save your object as NSData, so the logical approach is to get it back from the user defaults, unarchive it, update the properties, archive it and save it back to the user defaults.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this method dealing with a couple array that I can't seem to
I have this method that changes an larger image source on click. I need
I have this method to transfer files using a FTP Server: private void TransferNeededFiles(IEnumerable<string>
I have this method: internal static void AssignNewArrayItem(ref Xml.CLASSNAME[] Items, Xml.CLASSNAME Item) { if
If I have this method in object class: @OneToMany( fetch = FetchType.EAGER, cascade =
I have Customer class that make connection to db and save data to mysql.
I have this method for shrinking down an image for a website that I'm
I have a controller method CreateOrUpdate, this method is supposed to save the car
I have this app of mine that contains a section that will allow the
I want to have thread save method that returns a unique current Timestamp.Even when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.