[userDefault] userDefault
Ios/Tip & Library View Comments
[ userDefault ]
상황: userDefault를 사용해보자.
<해결 코드>
// Create strings and integer to store the text info
NSString
*firstName = [firstNameTextField
text
];
NSString
*lastName = [lastNameTextField
text
];
int
age = [[ageTextField
text
]
integerValue
];
// Create instances of NSData
UIImage
*contactImage = contactImageView
.image
;
NSData
*imageData = UIImageJPEGRepresentation(contactImage,
1
0
0
);
// Store the data
NSUserDefaults
*defaults = [
NSUserDefaults
standardUserDefaults
];
[defaults
setObject
:firstName
forKey
:
@"firstName"
];
[defaults
setObject
:lastName
forKey
:
@"lastname"
];
[defaults
setInteger
:age
forKey
:
@"age"
];
[defaults
setObject
:imageData
forKey
:
@"image"
];
[defaults
synchronize
];
NSLog(
@"Data saved"
);
NSUserDefaults
*defaults = [
NSUserDefaults
standardUserDefaults
];
NSString
*firstName = [defaults
objectForKey
:
@"firstName"
];
NSString
*lastName = [defaults
objectForKey
:
@"lastname"
];
int
age = [defaults
integerForKey
:
@"age"
];
NSString
*ageString = [
NSString
stringWithFormat
:
@"%i"
,age];
NSData
*imageData = [defaults
dataForKey
:
@"image"
];
UIImage
*contactImage = [
UIImage
imageWithData
:imageData];
의견: 유저디포트를 사용해보았다.
'Ios > Tip & Library' 카테고리의 다른 글
[customView] customview에서 값넘기기 (0) | 2014.09.08 |
---|---|
[tip]xcode 5.1.1 missing required architecture arm64 error (0) | 2014.09.08 |
Simulator 6.1 쓰레기파일들 정리하기.(tmp폴더) (0) | 2013.08.14 |
SQLite 랜덤하게 뿌리기(random()) (0) | 2013.05.22 |
Recent Comments