NSRange dataRange; NSInteger dataSize = pinData.length; NSInteger dataSplitCount = dataSize/DATA_SPLIT_SIZE; dataRange.length = DATA_SPLIT_SIZE; dataRange.location = 0; NSMutableArray *dataArray = [NSMutableArray array]; for(NSInteger cnt = 0;cnt<dataSplitCount;cnt++) { [dataArray addObject:[sendData subdataWithRange:dataRange]]; dataRange.location += DATA_SPLIT_SIZE; } // 最後のデータは、レングスを調整してから処理を行う dataRange.length = dataSize%DATA_SPLIT_SIZE; [dataArray addObject:[pinData subdataWithRange:dataRange]];
NSMutableData *receiveData;
// 受信データを保存する [receiveData appendData:data];
DataObject *receiveObject = [NSKeyedUnarchiver unarchiveObjectWithData: receiveData];
- (void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *)session { // セッションを保管 currentSession = session; // デリゲートのセット session.delegate = self; // データ受信時のハンドラを設定 [session setDataReceiveHandler:self withContext:nil]; // ピアピッカーを閉じる picker.delegate = nil; [picker dismiss]; if (osVersion >= 7.0) { // iOS7.0 if (self.isConnecting == NO) [self session:currentSession peer:peerID didChangeState:GKPeerStateConnected]; } } - (void)session:(id)session peer:(id)peerID didChangeState:(GKPeerConnectionState)state { switch (state) { case GKPeerStateAvailable: // (省略) break; case GKPeerStateConnecting: // (省略) break; case GKPeerStateConnected: // 接続完了 self.isConnecting = YES; // 接続完了後の処理をここに書く(省略) break; case GKPeerStateDisconnected: // (省略) break; case GKPeerStateUnavailable: // (省略) break; default: break; } }
NSInteger row = indexPath.row;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:1];
DataGroup *selectedObject = [[self fetchedResultsController] objectAtIndexPath:editGroupNo]; NSMutableArray *editArray = selectedObject.arrayObject; DataObject *editData = [[DataObject alloc]init]; [editArray addObject:editData]; NSMutableArray *saveArray = [NSMutableArray array]; NSInteger cnt,loopMax; loopMax = editArray.count; for (cnt=0; cnt<loopMax; cnt++) { [saveArray addObject:[editArray objectAtIndex:cnt]]; } selectedObject.pinArrayObject = saveArray; // saveメソッドで更新状態を確定 error = nil; if (![context save:&error]) { NSLog(@"error = %@", error); abort(); }
DataGroup *selectedObject = [[self fetchedResultsController] objectAtIndexPath:editGroupNo]; NSMutableArray *editArray = selectedObject.arrayObject; DataObject *editData = [editArray objectAtIndex:editItemNo]; selectedObject.pinArrayObject = nil; // saveメソッドで更新状態を確定 error = nil; if (![context save:&error]) { NSLog(@"error = %@", error); abort(); } editData.itemName = @"変更後の文字列"; NSMutableArray *saveArray = [NSMutableArray array]; NSInteger cnt,loopMax; loopMax = editArray.count; for (cnt=0; cnt<loopMax; cnt++) { [saveArray addObject:[editArray objectAtIndex:cnt]]; } selectedObject.pinArrayObject = saveArray; // saveメソッドで更新状態を確定 error = nil; if (![context save:&error]) { NSLog(@"error = %@", error); abort(); }