> On Jul 7, 2017, at 9:48 PM, Zhao Xin wrote:
>
> Thank you very much Marco. But What is “outside of an initializer” really
> bothers me. **Both** `func bar(keysAndValues:Dictionary)`
> works now. **Are they really outside ?**
Uhhh, that is certainly not
Thank you very much Marco. But What is “outside of an initializer” really
bothers me. **Both** `func bar(keysAndValues:Dictionary)`
works now. **Are they really outside ?**
struct Foo {
var keys = ["z","y","x"]
{
didSet {
keys.sort()
}
> init(keysAndValues:Dictionary) {
> self.keys.append(contentsOf: keysAndValues.keys)
> }
>
> Above code doesn't call `didSet` in playground. My .swift file is similar and
> didn't call `didSet` either. However, if without a struct, `didSet` is called.
“If
import Cocoa
struct Foo {
var keys = ["z","y","x"]
{
didSet {
keys.sort()
}
}
init(keysAndValues:Dictionary) {
self.keys.append(contentsOf: keysAndValues.keys)
}
}
let keysAndValues:Dictionary =
That will not work since R can be different types depending on T (R == (T,
T) for S2 and R == (T, T, T) for S3).
I guess Swift would have to support generic associated type for it to work:
protocol P {
associatedtype R
static func foo(_ v: T) -> R
}
struct S2 : P {
typealias R = (U, U)
Try using an associated type for the result of foo():
protocol P {
associatedtype R
static func foo(_ v: T) -> R
}
Slava
> On Jul 7, 2017, at 1:50 AM, Jens Persson via swift-users
> wrote:
>
> protocol P {
> // …
> // For example the following will not
It definitely should. Can you show the code where it wasn’t being called?
Thanks!
Jordan
> On Jul 7, 2017, at 00:31, Zhao Xin via swift-users
> wrote:
>
> Should Array's `append(_)` functions cause the array's `didSet`?
> In my own test, it did call `didSet` in
Nice!
The key is to have a non generic base class as storage for statics and a
subclass for generic types… brilliant.
I am definitely going to try this one.
Vladimir’s solution is also a nice fact to know. The key point of the compile
error message seems to be « static __stored__ « hence,
Here's yet another alternative. I read an article doing this very thing a
while back, it might be interesting to you:
http://radex.io/swift/nsuserdefaults/static/. It makes the key type a class
instead, and inherits from a non-generic parent class to which it adds the
static properties.
The gist
On 07.07.2017 14:02, Thierry Passeron via swift-users wrote:
Hi Everyone,
Using Swift 3.1, I was wondering if I could come up with something largely
inspired by Notification.Name to help me deal with UserDefaults so I started by
doing something like:
The only kind of solution I was able to
On 07.07.2017 5:50, David Baraff via swift-users wrote:
I thought I read that tuples would finally be hashable in swift 4, allowing for
them to be used in dictionaries/sets, but now that i google for it, i find no
mention of it.
are there any plans? so often i just want to quickly create a
Hi Everyone,
Using Swift 3.1, I was wondering if I could come up with something largely
inspired by Notification.Name to help me deal with UserDefaults so I started by
doing something like:
public struct DefaultsKey: RawRepresentable, Equatable, Hashable, Comparable {
public var rawValue:
Welcome to the group of people who thinks that the character from Monopoly had
a monocle, including myself. You've just experienced a transdimensional jump
from your universe without even notecing, but where Swift 4 actually had
hashable tuples. :)
Jokes aside, I haven't read anything about it
protocol P {
// …
// For example the following will not work:
// static func foo(_ v: T) -> R
// Is there some other way?
// …
}
struct S2 : P {
static func foo(_ v: T) -> (T, T) {
return (v, v)
}
}
struct S3 : P {
static func foo(_ v: T) -> (T, T, T)
Should Array's `append(_)` functions cause the array's `didSet`?
In my own test, it did call `didSet` in Playground. But in .swift files, it
didn't call.
Is this a known bug or something? Which is correct?
Xcode Version 9.0 beta 2 (9M137d)
swift --version
Apple Swift version 4.0
15 matches
Mail list logo