2016-09-28 3 views
0

私はsetObject:forKey:を使用して、タイプRresourceのオブジェクトをNSMutableDictionary:resourceLibに追加します。エントリが追加されたメソッドから離れるとNSMutableDictionaryエントリが破損しました

次に、私はすぐに実際に辞書にあるものを見て、それはOKです。

私は別のオブジェクトのメソッドに再びそれを見しようとすると、適切なキーが存在するが、プロパティ「URL」場合を含むエラーメッセージのリストの文字列への参照:

2016年9月28日11 :32:42.636種皮[760:16697] - [__ NSCFStringのURL]:未認識セレクタインスタンスに送信0x600000456350

Rresourceオブジェクトが次のように定義されますのViewControllerに

@interface Rresource : NSObject 
@property (nonatomic,strong) NSString* url; 
@property (nonatomic,strong)NSMutableArray* resourceNotesArray; 
@property(nonatomic,strong)NSString* name; 
@property(nonatomic,strong)NSString* resourceUniqueID; 
@property(nonatomic)BOOL isResourceDirty; 

この方法はNSMutableDictionaryにRresourceを追加

-(void)saveResource 
{ 
Rresource* resource = self.currentResource; 
Rresource* temp; 
if (resource) 
{ 
    if (resource.isResourceDirty) 
    { 
     [self.model.resourceLib setObject:resource forKey:resource.resourceUniqueID]; 
     temp = [self.model.resourceLib objectForKey:resource.resourceUniqueID]; 
    } 
} 

}

リソースとtempが正しく追加された情報を示す同じ情報が含まれています。

モデルのメソッドでは、上記のエラーメッセージが表示されます。

@property(nonatomic,strong)NSMutableDictionary* resourceLib; 

と::私もそれを策定するいくつかの時間を過ごした後、明らかに尋ねるのが難しいこの質問を発見した

@implementation Model 


- (instancetype)init 
{ 
self = [super init]; 
if (self) 
{ 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); 
    self.path = [[paths objectAtIndex:0] stringByAppendingString:@"/Application Support/E2"]; 
    BOOL exists = [[NSFileManager defaultManager] createDirectoryAtPath:self.path withIntermediateDirectories:NO attributes:nil error:nil]; 
    if (!exists) 
    { 
     [[NSFileManager defaultManager] createDirectoryAtPath:self.path withIntermediateDirectories:NO attributes:nil error:nil]; 
    } 
    self.resourceLibPath = [NSString pathWithComponents:@[self.path,@"resources"]]; 
    self.resourceLib = [[NSMutableDictionary alloc]init]; 
    self.noteLibPath = [NSString pathWithComponents:@[self.path, @"notes"]]; 
    self.noteLib = [[NSMutableDictionary alloc]init]; 
} 
return self; 

をモデルが含まれている

for (Rresource* resource in self.resourceLib) 
{ 
    NSString* string = resource.url; 
} 

。謝罪します。

私は約1週間、すべてを試しました。私は困惑している。

アイデア?

おかげ

this entry on Enumerationによると

答えて

0

、あなたは高速列挙の構文を使用して辞書を反復するとき、あなたはそのキーを反復処理しています。上のコードサンプルでは、​​値の列挙が発生していると仮定しています。あなたが効果的にやっているのは、オブジェクトをRresourceとしてキャストし、セレクタに送るのは実際のRresourceオブジェクトにしか反応できません。

これは、ループ修正する必要があります。

for (NSString* key in self.resourceLib) 
{ 
    NSString* string = [self.resourceLib objectForKey:key].url; 
} 
+0

それでした!どうもありがとう! –

関連する問題