-4

In My project first view controller is selecting school and city and after selecting, I will click on submit.

Then app will not ask it again unless I clear the app cache memory.Next page is login after entering the userid and password I will click on login.

Now when I start my app it will show me after login next page.

Now my question is how to clear the project cache memory while coding bcz I have saved it in NSUserDefaults ,whenever I run program some time it start from first view controller that is selecting school or sometimes it start from the login page and when I run it on iphoneSE,iphone5,6,7. It shows me different school backgroung in login page , I dont know solve this problem!

Selecting School and city view conroller->login page->enter into app

Hardik Thakkar
  • 15,269
  • 2
  • 94
  • 81
sumi
  • 3
  • 4

1 Answers1

0

It sounds like you need to remove some data from NSUserDefaults.

From This answer on StackOverflow:

The easiest way to clear NSUserDefaults is by using one of the following:

Option 1

[[NSUserDefaults standardUserDefaults] setPersistentDomain:[NSDictionary dictionary] forName:[[NSBundle mainBundle] bundleIdentifier]];

Option 2

NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];

Or if you're using Swift:

if let bundleID = Bundle.main.bundleIdentifier { UserDefaults.standard.removePersistentDomain(forName: bundleID) }

Removing a single entry

To remove a single entry from NSUserDefaults, use the following:

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"preferenceName"];

Will Jones
  • 1,861
  • 13
  • 24
  • Hi ! Thanks for your answer ! But I wanted to know how to clear the cache memory of project without code,while running it ,the requirement is the when I select city and school from the first page it will store that name in NSUserdefault and It won't ask it again whenever we run app ,for that we need to clear app cache memory .while running project on simulator I selected city and school now I wanted to run it again from start bcz I have selected city and school so I wont able to select it again ,now it start from loging page i.,e second page ! – sumi Jun 25 '18 at 09:16
  • I don't understand what you mean by app cache memory. Whenever you store anything in NSUserDefaults it stays there until it's explicitly removed by code, or the app is uninstalled. There's no "reset" button that'll remove it. You could potentially pass a launch argument and read this value from the `[[NSProcessInfo processInfo] arguments]` collection and dependent upon the value, run the code I provided above to clear the NSUserDefaults/remove the value(s) you need to remove. – Will Jones Jun 25 '18 at 11:08
  • Thanks for your reply ! – sumi Jun 26 '18 at 05:13