2014-05-09 3 views
-2

NSUserDefaults에 id 유형 객체 값을 저장하려고합니다.NSUserDefaults에 id 유형 객체 저장

-(IBAction)sendOrderReady:(id)sender 
{ 
NSUserDefaults *d = [NSUserDefaults standardUserDefaults]; 
[d setValue:sender forKey:@"sender"]; 
// [d setObject:sender forKey:@"sender"]; 
[d synchronize]; 
} 
+0

의 인스턴스에 포장해야하는 다른 형태의 객체를 저장하려면 NSUserDefault에서 버튼 객체를 저장 하시겠습니까? – Dilip

+0

정말 저장하고 싶은 점은 무엇입니까? – manujmv

+0

가능한 [NSUserDefaults에서 사용자 지정 개체를 저장하는 방법] 복제본 (http://stackoverflow.com/questions/2315948/how-to-store-custom-objects-in-nsuserdefaults) – Hemang

답변

4
아이디 객체가 위의 경우 중 하나가 아닌 경우

The NSUserDefaults class provides convenience methods for accessing common types such as floats, doubles, integers, Booleans, and URLs. A default object must be a property list, that is, an instance of (or for collections a combination of instances of): NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. If you want to store any other type of object, you should typically archive it to create an instance of NSData.

그래서, 당신은 그들 중 하나로 변환해야합니다 NSUserDefaults 클래스의 설명에서

this question is what exactly you're looking for.

-1
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 

// saving an NSString 
[prefs setObject:@"iPhone" forKey:@"keyToLookupString"]; 

// saving an NSInteger 
[prefs setInteger:442 forKey:@"integerKey"]; 

// saving a Double 
[prefs setDouble:5.15 forKey:@"doubleKey"]; 

// saving a Float 
[prefs setFloat:123.45678 forKey:@"floatKey"]; 

// This is suggested to synch prefs, but it is not needed 
[prefs synchronize]; 
0

NSUserDefaults를 사용하면 다음 클래스 유형의 개체를 저장할 수 있습니다.

을 NSData,있는 NSString,의 NSNumber,있는 NSDate, NSArray를, NSDictionary와

당신은 당신이 그것을 보관하거나 당신이 원하는 이유는 무엇을 NSData

관련 문제