keypaths Questions

2

Solved

I made a program to calculate the total width/height of views (sometimes I want the total width, sometimes I want the total height). The only catch is: If I'm calculating the width, I want to add a...
Stonge asked 15/8, 2021 at 20:20

2

Solved

Consider the following snippet of code class A { var value: Int? } let a: A? = A() let kp = \A.value a?[keyPath: kp] = 10 print(a?.value) This works perfectly and Optional(10) is printed as ...
Obryan asked 22/7, 2019 at 7:38

2

I have an array of enum cases, where each case has a keyPath property, which returns an AnyKeyPath matching the classes property with the same name as the enum case: protocol PathAccessor: CodingK...
Cherubini asked 24/1, 2018 at 16:40

5

Solved

I have a string like this: $string = 'one/two/three/four'; which I turn it into a array: $keys = explode('/', $string); This array can have any number of elements, like 1, 2, 5 etc. How can I ...
Clamper asked 22/9, 2011 at 0:53

2

Solved

I've been trying to find an example, but what I've seen doesn't work in my case. What would be the equivalent of the following code: object.addObserver(self, forKeyPath: "keyPath", options: [.ne...
Haste asked 29/11, 2017 at 22:34

1

Solved

It seems like it should be possible to use an array of KeyPaths as sort keys to sort an array of Swift structs using an arbitrary number of sort keys. Conceptually, it's simple. You define an arra...
Ecotone asked 2/5, 2018 at 13:50

2

I'm having some trouble getting the new KVO syntax right. According to the Apple documentation: Create an observer for the key path and call the observe(_:options:changeHandler) method. For mor...
Waac asked 29/3, 2018 at 18:47

3

Solved

I'm aware of the limitations of generics in Swift and why they exist so this is not a question about compiler errors. Rather, I occasionally run into situations that seem as though they should be p...
Guernica asked 16/2, 2018 at 2:27

2

Solved

I was very happy to find Swift 3's implementation of #keyPath(), which will eliminate typos and enforce at compile time that the key path actually exists. Much better than manually typing Strings. ...
Eikon asked 8/2, 2017 at 20:15

1

Solved

I would like to convert these strings into a combined nested array: array( 'item1:item2:itemx', 'item1:item2:itemy', 'itemz' ) To array( 'item1' => array( 'item2' => array( 'itemx' =&g...
Rameau asked 27/8, 2014 at 20:8
1

© 2022 - 2025 — McMap. All rights reserved.