I notice that Swift Data type's hashValue collision when first 80 byte of data and data length are same because of the Implementation only use first 80 bytes to compute the hash.
https://web.archive.org/web/20120605052030/https://opensource.apple.com/source/CF/CF-635.21/CFData.c
also, even if hash collision on the situation like this, I can check data is really equal or not by ==
does there any reason for this implementation(only use 80 byte of data to make hashValue)?
test code is under below
let dataArray: [UInt8] = [
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
]
var dataArray1: [UInt8] = dataArray
var dataArray2: [UInt8] = dataArray
dataArray1.append(contentsOf: [0x00, 0x00, 0x00, 0x00])
dataArray2.append(contentsOf: [0xff, 0xff, 0xff, 0xff])
let data1 = Data(dataArray1)
let data2 = Data(dataArray2) // Only last 4 byte differs
print(data1.hashValue)
print(data2.hashValue)
print(data1.hashValue == data2.hashValue) // true
print(data1 == data2) // false
Post
Replies
Boosts
Views
Activity
my Date type data is "2024-12-28 15:00:00 +0000" and when I use Date formatter to format date with timezone TimeZone(identifier: "Asia/Seoul"), date formatter return wrong year like below
(lldb) po print(date); let formatter = DateFormatter(); formatter.timeZone = TimeZone(identifier: "Asia/Seoul"); formatter.dateFormat = "YYYY-MM-dd"; formatter.string(from: date)
2024-12-28 15:00:00 +0000
"2025-12-29"
(lldb) po print(date); let formatter = DateFormatter(); formatter.timeZone = .gmt; formatter.dateFormat = "YYYY-MM-dd"; formatter.string(from: date)
2024-12-28 15:00:00 +0000
"2024-12-28"
until previous version of the Xcode, I can see the backtrace of view by edit scheme -> Diagnostics -> Logging -> check Malloc Stack and select All Allocation and Free History` but the option just gone in Xcode 16.
when audio file's magic number is 49443302 not 49443303, AVAudioPlayer's duration property return wrong value,
actually it cause by engiTunSMPB but I want to know why it happen only in ID3 version 2 (49443302)
example: only difference in two mp3 file is the magic number
and check the duration returns this result
source code under here
ContentView.swift
I tried to show spatial photo on my application by swiftUI's Image but it just show flat version of it even I Use Vision Pro,
so, how can I show spatial photo to users,
does there any options for this?
does it possible to run macOS application such as Xcode on VisionOS?
it's really cool to use only the Vision Pro(not with MacBook) to work!
and kind of curious about permission for terminal use!
this test fail on the specific device which disabled "Date & Time -> 24-Hour Time" and location is Japan, and when I set the locale, it runs fine on that specific device to, and I am curious what makes this happen, so anybody know the reason please help
import XCTest
final class DateFormatterTest: XCTestCase {
func testDateFormatter() throws {
let sendTime = "2023-04-25T02:07:29"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
// dateFormatter.locale = Locale(identifier: "en_US_POSIX") // test fail until I set locale
let result = dateFormatter.date(from: sendTime)
XCTAssertNotNil(result)
}
}