Notice
Recent Posts
Recent Comments
Link
투케이2K
100. (swift/xcode) String bytes 를 사용해 Data 값을 String 문자열로 형변환 수행 실시 본문
[개발 환경 설정]
개발 툴 : XCODE
개발 언어 : SWIFT

[소스 코드]
// MARK: - [테스트 함수 정의]
func testMain() {
print("")
print("===============================")
print("[ViewController >> testMain() :: 테스트 함수 수행]")
print("===============================")
print("")
// [초기 변수 선언 실시]
var dataValue : Data = Data()
dataValue.append(104)
dataValue.append(101)
dataValue.append(108)
dataValue.append(108)
dataValue.append(111)
// [String bytes 사용해 바이트 값을 문자열로 데이터 형변환 실시]
let strValue = String(bytes: dataValue, encoding: .utf8)!.trimmingCharacters(in: .controlCharacters)
// [로그 출력 실시]
print("")
print("===============================")
print("[ViewController >> testMain() :: 로그 출력 실시]")
print("[strValue :: \(strValue)]")
print("===============================")
print("")
}
[결과 출력]

반응형
'Swift' 카테고리의 다른 글
Comments