hippietrail
hippietrail
Explore posts from servers
TSDThe Swift Den
Created by hippietrail on 9/9/2023 in #swift-development
Can progress reporting be added to this style of https transfer?
but it seems to actually be less effort to use the old continuation method and both ways are equally fast. here's the great answer I got on Stack Overflow https://stackoverflow.com/a/77072098/527702
5 replies
TSDThe Swift Den
Created by hippietrail on 9/9/2023 in #swift-development
Can progress reporting be added to this style of https transfer?
the answer is yes instead of
let (data, _) = try await URLSession.shared.data(for: request)
let (data, _) = try await URLSession.shared.data(for: request)
use
let (asyncBytes, response) = try await URLSession.shared.bytes(from: url)
let (asyncBytes, response) = try await URLSession.shared.bytes(from: url)
then you can read the bytes byte-by-byte or line-by-line or probably other ways
for try await byte in bytes {
for try await byte in bytes {
or
for try await lines in bytes.lines {
for try await lines in bytes.lines {
then you can report progress either for each one, or keep track of how many calls/bytes/lines/etc or time elapsed to decide how often report progress
5 replies
TSDThe Swift Den
Created by hippietrail on 9/9/2023 in #swift-development
Can progress reporting be added to this style of https transfer?
I'm assuming i'm going to need a delegate. but so for i've only used those in gui apps and i haven't found an example yet how to make/use one for my case
5 replies
TSDThe Swift Den
Created by hippietrail on 9/9/2023 in #swift-development
Can progress reporting be added to this style of https transfer?
the code I started with was using a semaphore and I either assumed or read that was the old way and these days I should use async/await. Other examples I can find are for GUI apps (I'm doing commandline); or they used RunLoop, which I also assumed would be outdated
5 replies
TSDThe Swift Den
Created by iwontchill on 9/4/2023 in #swift-development
How to Rename a Project/App in Xcode
The way I do it is to close the project in Xcode and open it in VSCode where I do a search and replace in files. Carefully.
3 replies
TSDThe Swift Den
Created by hippietrail on 8/27/2023 in #swift-development
How to position vertical Slider
Thanks. It's just for a toy project to help me learn my way around the UI so not a big deal. I will learn custom controls later.
25 replies
TSDThe Swift Den
Created by hippietrail on 8/27/2023 in #swift-development
How to position vertical Slider
You can see the bounding box for the slider I want aligned on the right edge of the window does not match the slider itself.
25 replies
TSDThe Swift Den
Created by hippietrail on 8/27/2023 in #swift-development
How to position vertical Slider
No description
25 replies
TSDThe Swift Den
Created by hippietrail on 8/27/2023 in #swift-development
How to position vertical Slider
Yes I could also get a vertical slider in the centre of the display, but being able to align it like any normal control was well beyond my abilities as a newcomer.
25 replies
TSDThe Swift Den
Created by hippietrail on 8/27/2023 in #swift-development
How to position vertical Slider
Yes I found that one. Two answers involve custom slider libraries which will tend to have differences from the standard ones. The other one is much more promising involving swapping horizontal and vertical fields, but unlike native horizontal ones you have to pass the values in for those fields. And the newest comment on it says it doesn't work anymore. I've concluded there isn't really a native solution and it's intentional. At first I thought they designed it so you would "just" rotate it, but now I can see there is no "just" (-:
25 replies
TSDThe Swift Den
Created by hippietrail on 8/27/2023 in #swift-development
How to position vertical Slider
The more I look into this there more I conclude that vertical sliders have just gone out of fashion. Mac AppKit's NSSlider supports them, but iOS UIKit's UISlider doesn't.
25 replies
TSDThe Swift Den
Created by hippietrail on 9/15/2022 in #swift-development
How to pass parameter to custom iterator
figured it out. i thought i had to pass the parameter to AnySequence or AnyIterator but i only have to pass it to windows():
extension Array {

func windows(width: Int) -> AnySequence<ArraySlice<Element>> {
return AnySequence({ () -> AnyIterator<ArraySlice<Element>> in
var index = self.startIndex

return AnyIterator({
if index > self.count - width {
return nil
}

let result = self[index..<index + width]

self.formIndex(after: &index)

return result
})
})
}

}

let seq = [1,11,333,33,5,623,123,44,7,444]
for val in seq.windows(width:4) {
print(val)
}
extension Array {

func windows(width: Int) -> AnySequence<ArraySlice<Element>> {
return AnySequence({ () -> AnyIterator<ArraySlice<Element>> in
var index = self.startIndex

return AnyIterator({
if index > self.count - width {
return nil
}

let result = self[index..<index + width]

self.formIndex(after: &index)

return result
})
})
}

}

let seq = [1,11,333,33,5,623,123,44,7,444]
for val in seq.windows(width:4) {
print(val)
}
2 replies