私は2つのモデル間に1対多の関係があります。user <-->> followers
フォロワーテーブルはuserId
sで構成されています。関連するユーザーをこれらのユーザーに取得するためにフェッチリクエストを作成したいと思いますuserId
。私の述語は現在次のようになっています:
predicate = [NSPredicate predicateWithFormat:@"ANY userId IN %@", self.user.followers];
これにより、結果は0になります。この述語はどのように見えるべきでしょうか?
アップデート
フォロワーオブジェクトをユーザーに追加するために使用するコード(JSONデータから):
+ (void)insertFollowersFromDict:(NSDictionary *)dictionary forUser:(User *)user inManagedObjectContext:(NSManagedObjectContext*)moc
{
NSArray *followers = [dictionary objectForKey:@"data"];
if (followers.count != 0) {
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Follower" inManagedObjectContext:moc];
for (NSString *followerId in followers) {
Follower *newFollower = [[Follower alloc] initWithEntity:entityDescription insertIntoManagedObjectContext:moc];
NSNumberFormatter * numberFormatter = [[NSNumberFormatter alloc] init];
newFollower.user = [User findUser:[numberFormatter numberFromString:followingId] inManagedObjectContext:moc];
[user addFollowersObject:newFollower];
}
}
}
テーブルビューでセルを構成するために使用するコード:
// This for some reason always result in the same user.
Follower *follower = [self.fetchedResultsController objectAtIndexPath:indexPath];
User *cellUser = follower.user;
// Always self.user
cell.text = cellUser.name
------------------------
I Anders I
------------------------
------------------------
I Anders I
------------------------
なぜこれが起こるのかわかりません。