0
Swift 3의 데이터에서 포인터를 사용하는 방법을 알아 내려고합니다. OBJ-C에서 10 값 파일의 4 번째 값을 수정하는 다음과 같은 간단한 방법이 있습니다. . 스위프트 3에서 어떻게하면 좋을까요?Swift 3에서 포인터를 사용하여 데이터 수정
- (void) modifyFourthValueInFile:(NSString*)filePath {
//filePath is a file that contains 10 SInt16 values
NSData *data = [NSData dataWithContentsOfFile:filePath];
SInt16 *ourPointer = (SInt16*)data.bytes;
ourPointer += 3; // get the 4th value
*ourPointer = 1234; // modify the 4th value
[data writeToFile:filePath atomically:YES];
}
: [3] = 1234 – kishdude
@kishdude i16ptr : 당신을 맞습니다. 나중에 깨달았습니다. 버퍼의 장점은 다음과 같습니다. 1) 경계 검사 2) 컬렉션이므로 요소를 반복 할 수 있습니다. –