ios


Read values from localized file iOS


I have created a localized string file which contains Error message in Key/Value Pair. What I just want to read values on key basis just like Plist.
Here is content of my Localized file
"SERVICE_ERROR" = "Some error occurred while processing your request, Please try later";
And this is how I am saving this string in user preferences
[ErrorManager setLastErrorInPreferences:NSLocalizedString(#"SERVICE_ERROR", nil)];
Here is setLastErrorInPreferences method
+ (void)setLastErrorInPreferences:(id)errorString {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSDate *now = [NSDate date];
NSString *errorStringWithTime = [NSString stringWithFormat:#"On %#:\n%#", now, errorString];
[prefs setObject:errorStringWithTime forKey:KlastError];
}
But its not working. Its just saving the key as it is. Its not reflecting the value of this key in user preferences.Kindly let me know what I am missing.
I am assuming you have a Localizable.strings file. No other name will work.Change the content of your localizable file from
"SERVICE_ERROR" = "Some error occurred while processing your request, Please try later";
to
SERVICE_ERROR = "Some error occurred while processing your request, Please try later";
(Remove "" from your key SERVICE_ERROR and keep a semi-colon at the end ;)
Also show what your setLastErrorInPreferences is doing?
Usage
NSString* error = NSLocalizedString(#"SERVICE_ERROR", nil);
NSLog(#"%#",error);
It worked fine.
My File
EDIT
Fetching the errorValue. Make some method in your ErrorManager class and fetch it from there as kLastError won't be available in your Controller class.
NSString* yourError = [[NSUserDefaults standardUserDefaults] stringForKey:KlastError];

Related Links

addSubView - adding a button inside a UIView adds the same button for it's SuperView as well
How can I access the associated values of SwiftyDropbox errors?
CNSaveRequest returns “Updated Record Does Not Exist”
iOS when one views height increase with code , alignment is deteriorating
iCloud KVStore - Code Signing Entitlements Error
Swift UITableView not showing all result
Remove All Cell Accessories in UITableView in Swift 2
iOS9 Developer Trust App No Internet Connection Error
appMessagesGetIsSupported is false for appMessagesGetIsSupported
Making a mixed Objective-C & Swift Framework
How do i access the textField in my alertView? Trying to see if password matches current user. parse/swift
How to play MP3 From URL in iOS
Restkit 0.24.1 POST to Server and get response synchronously
UITableView has extra space on top during “pull down to refresh”
KeychainItemWrapper class getting error in ios 9
library not found for -lCloudinary

Categories

HOME
math
elastic-beanstalk
dynamic-programming
printing
simulated-annealing
dicom
crf
x-editable
android-sqlite
google-cloud-dataproc
twitter-digits
antlr4
cross-domain
tin-can-api
predictionio
akka.net
autofac
eloqua
higher-order-functions
graphcool
lexikjwtauthbundle
formio
gyroscope
contains
dotnetbar
amazon-cloudfront
nice-language
confidence-interval
padding
weather-api
f2py
codeceptjs
python-behave
scatter-plot
scom
react-redux-form
swipe
reed-solomon
roo
nav
gridstack
executorservice
confirm
jetty-9
spring-saml
otroslogviewer
stateful
edeliver
gradle-tooling-api
integer-programming
php-deployer
name-mangling
spring-form
gcc4.8
ammonite
android-identifiers
itamae
android-chips
data-fitting
struts1
benerator
pypyodbc
webpack-hmr
training-data
storage-duration
asp.net-authorization
uac
thinktecture-ident-server
clipping
openocd
biojava
mtp
protected
mailx
cvc4
bloodhound
keypad
solr-boost
textmatching
windows-universal
android-design-library
publish-actions
acts-as-taggable-on
ramdisk
pdf-scraping
nawk
external-dependencies
rte
jquery-data
route-me
source-highlighting
sizzle
timespan
mixing
ed
intel-8080
mate
closest
codi
program-transformation
arraycopy
wmd
project-settings
cracker
non-relational-database
stsadm

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App