Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- NSMutableDictionary *dictionary = nil;
- //The line below shows the error
- SiteValue* person1 = [SiteValue siteValueWithUsername: @"person1" andPassword: @"123" andCount: 0];
- }
- return 0;
- }
- @interface SiteValue : NSObject
- +(SiteValue*) siteValueWithUsername: (NSString *)username andPassword: (NSString *)password andCount: (int) count;
- @end
- #import "SiteValue.h"
- @implementation SiteValue
- //Defining the three varibles
- NSString* username1;
- NSString* password1;
- int count1;
- -(id)initWithUsername: (NSString *)username
- andPassword: (NSString *)password
- andCount: (int) count {
- self = [super init];
- if (self) {
- username1 = username;
- password1 = password;
- count1 = count;
- }
- return self;
- }
- //Setters and Getters for each of the three variables
- -(void) setUsername: (NSString*) username {
- username = username;
- }
- -(NSString*) username {
- return username1;
- }
- -(void) setPassword: (NSString*) password {
- password = password;
- }
- -(NSString*) password {
- return password1;
- }
- -(void) setCount: (int) count{
- count = 0;
- }
- -(int) count {
- return count1;
- }
- +(SiteValue*) siteValueWithUsername: (NSString *)username andPassword: (NSString *)password andCount: (int) count {
- return [[SiteValue alloc]
- initWithUsername: username andPassword: password andCount: count];
- }
- //Other methods
- -(BOOL) addUser: (NSMutableDictionary **) dictionary addKey: (NSString *)key {
- //Check if duplicate object, if not create the dictionary or add object
- //Create the dictionary
- if (!*dictionary)
- {
- *dictionary = [[NSMutableDictionary alloc] init];
- }
- for (NSString *key in *dictionary) {
- SiteValue *value = [*dictionary objectForKey: key];
- if ([[value username] isEqualToString: username1]) {
- NSLog (@"Error, Username Already Exists!");
- return NO;
- }
- }
- [*dictionary setObject:self forKey: key];
- NSLog (@"User Successfully Added!");
- return YES;
- }
- -(void) incrementCount{
- count1++;
- }
- // Print the dictionary
- -(void) print: (NSMutableDictionary *) dictionary{
- for (SiteValue *SiteValue in dictionary) {
- NSLog (SiteValue.username, SiteValue.password, SiteValue.count);
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement