logo
down
shadow

Swift REPL Unexpected Behaviour


Swift REPL Unexpected Behaviour

By : user2955885
Date : November 22 2020, 10:48 AM
wish of those help All that's happening here is that the REPL is letting you look inside Swift at some of the underlying efficiencies. p is stored as some sort of function composition. When evaluation is needed, it is evaluated. If you didn't want to see the sausage being made, you should not have entered the sausage factory.
code :


Share : facebook icon twitter icon
Swift 2 Regex unexpected behaviour

Swift 2 Regex unexpected behaviour


By : Recon
Date : March 29 2020, 07:55 AM
should help you out The first problem is that let html: NSString? = "..." is an optional, and therefore String(html) evaluates to
code :
Optional(...)
let valPattern = "<td>(.*?)<\\/td>|<td.*?\"(.*?)\">.*?<\\/td>"
let html: NSString = "<tbody><tr><td sortkey=\"20151003\">03 Oct 2015</td><td>8,852.61</td><td>1,383.68</td><td>Text</td></tr><tr><td sortkey=\"20151004\">04 Oct 2015</td><td>2,577.14</td><td>282.49</td><td>Text</td></tr></tbody>"

let rowPattern = "<tr>\\s*<td s.*?<\\/tr>"
let rowRegex = try! NSRegularExpression(pattern: rowPattern, options: [])
let rowMatches = rowRegex.matchesInString(String(html), options: [], range: NSMakeRange(0, html.length))

for rowMatch in rowMatches {
    let rowString: NSString = html.substringWithRange(rowMatch.range)

    print("rowString=\(rowString)")

    let valPattern = "<td>(.*?)<\\/td>|<td.*?\"(.*?)\">.*?<\\/td>"
    let valRegex = try! NSRegularExpression(pattern: valPattern, options: [])
    let valMatches = valRegex.matchesInString(String(rowString), options: [], range: NSMakeRange(0, rowString.length))

    for valMatch in valMatches {
        if valMatch.rangeAtIndex(1).location != NSNotFound {
            let value = rowString.substringWithRange(valMatch.rangeAtIndex(1))
            print(value)
        }
        if valMatch.rangeAtIndex(2).location != NSNotFound {
            let value = rowString.substringWithRange(valMatch.rangeAtIndex(2))
            print(value)
        }
    }
}
rowString=<tr><td sortkey="20151003">03 Oct 2015</td><td>8,852.61</td><td>1,383.68</td><td>Text</td></tr>
20151003
8,852.61
1,383.68
Text
rowString=<tr><td sortkey="20151004">04 Oct 2015</td><td>2,577.14</td><td>282.49</td><td>Text</td></tr>
20151004
2,577.14
282.49
Text
Swift Optional Template Type unexpected parameter behaviour

Swift Optional Template Type unexpected parameter behaviour


By : headtop
Date : March 29 2020, 07:55 AM
Does that help I think what you want to do is make convertVal function's parameter and return type optional and the Converters type a regular String instead.
code :
class Converter<T> {
    init() {}

    func convertVal(_ val: T?) -> T? {
        print("val: \(val)")
        print(type(of: val))
        print("val is nil: \(val == nil)")
        return val
    }
}

let firstStr: String? = nil

let converter = Converter<String>()
var str = converter.convertVal(firstStr)
val: nil
Optional<String>
val is nil: true
CollectionView cell unexpected behaviour swift

CollectionView cell unexpected behaviour swift


By : Phil Head
Date : March 29 2020, 07:55 AM
I hope this helps . Found the problem. I cancelled the elsestatement after if statement in cellForItemAtas now prepareForReuseis setting the default cell. It all now works as expected. The final function is:
code :
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "timeSlotCell", for: indexPath) as! TimeSlotCollectionViewCell

        // Configure the cell
        cell.timeLabel.text = timeSlotArray[indexPath.row]

        cell.cellId = Int("\(String(describing: self.selectedDate))" + self.timeStringToStringConvert(timeSlotArray[indexPath.row]))

        if bookedTimeSlotsArray.count > 0 {
            for index in 0...bookedTimeSlotsArray.count - 1 {
                let bookingId = bookedTimeSlotsArray[index].bookingId

                if cell.cellId == bookingId {
                    print("   match found")
                    print("Index is: \(index)")
                    print("cell time is: \(timeSlotArray[indexPath.row])")
                    print("time slot cell id is: \(String(describing: cell.cellId))")
                    print("booking id: \(bookingId)")
                    cell.backgroundColor = UIColor.red.withAlphaComponent(0.3)
                }
            }
        }
        return cell
    }
Swift Combine: Unexpected backpressure behaviour with zip operator

Swift Combine: Unexpected backpressure behaviour with zip operator


By : user3572016
Date : March 29 2020, 07:55 AM
I wish this help you It seems that the Sequence publisher is just unrealistic. It doesn't seem to respond to back pressure; it just spews out the whole sequence at once, which makes no sense in a world where publication is supposed to be asynchronous. If you change Int.max to 3 there's no problem. :) I don't know whether it's a bug or just a flaw in the whole notion of a Sequence publisher.
However, there's really no issue for your actual use case, because there is a much better way to assign a successive number to each emission from the Subject, namely scan.
code :
func delay(_ delay:Double, closure:@escaping ()->()) {
    let when = DispatchTime.now() + delay
    DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
}
class ViewController : UIViewController {
    var storage = Set<AnyCancellable>()
    override func viewDidLoad() {
        super.viewDidLoad()
        let subject = PassthroughSubject<String, Never>()
        subject.scan(("",0)) {t,s in (s,t.1+1)}
            .sink { print($0.0, $0.1)
            }.store(in:&storage)
        delay(1) {
            subject.send("a") // a 1
            delay(1) {
                subject.send("b") // b 2
            }
        }
    }
}
    var storage = Set<AnyCancellable>()
    let subject = PassthroughSubject<String, Never>()
    override func viewDidLoad() {
        super.viewDidLoad()
        var counter = 1
        subject
            .sink {print($0, counter); counter += 1}
            .store(in:&storage)
        delay(1) {
            self.subject.send("a") // a 1
            self.subject.send("b") // b 2
        }
    }

Swift REPL: how to save/load the REPL state? (a.k.a. suspend/resume, snapshot, clone)

Swift REPL: how to save/load the REPL state? (a.k.a. suspend/resume, snapshot, clone)


By : user5050359
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Maybe this could help you a bit.
Just found out actually Swift REPL save current session in a file.
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org