Advertisement
Guest User

Untitled

a guest
Feb 24th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. int main(int argc, const char * argv[]) {
  2. @autoreleasepool {
  3. NSMutableDictionary *dictionary = nil;
  4.  
  5. //The line below shows the error
  6. SiteValue* person1 = [SiteValue siteValueWithUsername: @"person1" andPassword: @"123" andCount: 0];
  7.  
  8. }
  9. return 0;
  10.  
  11. }
  12.  
  13. @interface SiteValue : NSObject
  14.  
  15. +(SiteValue*) siteValueWithUsername: (NSString *)username andPassword: (NSString *)password andCount: (int) count;
  16.  
  17. @end
  18.  
  19. #import "SiteValue.h"
  20.  
  21. @implementation SiteValue
  22.  
  23. //Defining the three varibles
  24. NSString* username1;
  25. NSString* password1;
  26. int count1;
  27.  
  28. -(id)initWithUsername: (NSString *)username
  29. andPassword: (NSString *)password
  30. andCount: (int) count {
  31. self = [super init];
  32. if (self) {
  33. username1 = username;
  34. password1 = password;
  35. count1 = count;
  36. }
  37. return self;
  38. }
  39.  
  40. //Setters and Getters for each of the three variables
  41. -(void) setUsername: (NSString*) username {
  42. username = username;
  43. }
  44.  
  45. -(NSString*) username {
  46. return username1;
  47. }
  48.  
  49. -(void) setPassword: (NSString*) password {
  50. password = password;
  51. }
  52.  
  53. -(NSString*) password {
  54. return password1;
  55. }
  56.  
  57. -(void) setCount: (int) count{
  58. count = 0;
  59. }
  60.  
  61. -(int) count {
  62. return count1;
  63. }
  64.  
  65.  
  66. +(SiteValue*) siteValueWithUsername: (NSString *)username andPassword: (NSString *)password andCount: (int) count {
  67. return [[SiteValue alloc]
  68. initWithUsername: username andPassword: password andCount: count];
  69. }
  70.  
  71. //Other methods
  72. -(BOOL) addUser: (NSMutableDictionary **) dictionary addKey: (NSString *)key {
  73. //Check if duplicate object, if not create the dictionary or add object
  74. //Create the dictionary
  75. if (!*dictionary)
  76. {
  77. *dictionary = [[NSMutableDictionary alloc] init];
  78. }
  79. for (NSString *key in *dictionary) {
  80. SiteValue *value = [*dictionary objectForKey: key];
  81. if ([[value username] isEqualToString: username1]) {
  82. NSLog (@"Error, Username Already Exists!");
  83. return NO;
  84. }
  85. }
  86. [*dictionary setObject:self forKey: key];
  87. NSLog (@"User Successfully Added!");
  88. return YES;
  89. }
  90.  
  91.  
  92. -(void) incrementCount{
  93. count1++;
  94. }
  95.  
  96. // Print the dictionary
  97. -(void) print: (NSMutableDictionary *) dictionary{
  98. for (SiteValue *SiteValue in dictionary) {
  99. NSLog (SiteValue.username, SiteValue.password, SiteValue.count);
  100. }
  101. }
  102.  
  103.  
  104. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement