Here's the scenario. I have three classes: A, B, and C. Class A is a subclass of B. Class C needs to pass one of its instance variables to class A (let's call it b). I want to make sure that it happens when C initializes A to make sure that I won't…
Here is the code I have in a playground
import UIKit
extension CIFilter {
convenience init(name: String, dummy: String) {
self.init(name: name)
}
}
let filter = CIFilter(name: "CIGaussianBlur", dummy: "dummy")
It crashes (exception)…
I'm defining an extension on Array to override Slice creation:
struct S {
private var array: [T] = []
private var first = 0
private var len = 0
init(_ array: [T], _ range: Range? = nil) {
self.array = array
…
I am creating an extension for NSURL that basically validates that a URL exists and returns a valid site.
I am using NSURLConnection.sendAsynchronousRequest(...) for this process to actually check the http header response, and it works…
This question led me to uncover this issue.
If I have two initializers with the same signature in the same class in different modules, how can I specify which one I want to call? To use the same example as in that question, say I declare a…
I am following along with this tutorial in order to create an async generic network layer. I got the network manager working correctly.
https://betterprogramming.pub/async-await-generic-network-layer-with-swift-5-5-2bdd51224ea9
As I try to implement…
I have a enum that has an integer representation, and I am going to be iterating over this type in a for loop. I was loop to get both the min and max int value from the enum
private enum PreloadedArrayDataIndex: Int, CaseIterable {
case…
Abstract
The requirements of the app I'm working on make me use DateComponents as a bridge when working with time - specifically hours and minutes. Another requirement made me make DateComponents: Comparable and that's when I found some nasty…
I have a class where some subclasses conform to Protocol1. The API from Protocol1 is sufficient to implement Protocol2. I want to do something like below, where I can define a default implementation of Protocol2 when an instance of my class…
I am trying to style a Text Editor in SwiftUI to look like a Material Design element. Currently, I'm struggling with the floating label.
I cannot figure out how to capture the editing state of Text Editor.
This is the code of the app:
struct…
I'm trying to create an extension on Set that uses a where clause so that it only works on a struct I have that accepts a generic. But I keep running into errors about it the extension wanting the generic to be defined in the struct
In this example…
I like to separate soms function and var from a enum and thought this was a way. (Just sample code)
This results in a compile error "Type 'Self' has no member 'allCases'"
public protocol EnumFunctions: Hashable {
static var numOfCases: Self {…
Consider the following situation:
protocol P {
associatedtype T = String
func f()
}
extension P {
func f() {print("I want to reuse this function")}
}
class A: P {
func f() {
(self as P).f() // can't compile
…
Can anybody tell me if it is possible to create a deferred completable in a concat operator.
I want to fetch a session, and after this load a user with the corresponding session id.
SessionAPI.post(email: email, password: password)
UserAPI.get(id:…
I don't seem to find a way to easily add unit tests to Sirikit extension.
I would like to be able to test Siri implementation in my app with some unit test to be able to assure myself of non regression with the evolution of the feature but I can't…