[swift-users] Initializer accessing self

2017-02-01 Thread Brandon Knope via swift-users
I am at a loss:

Why does this not work:
class Test {
let timer: Timer!

init() {
timer = Timer.scheduledTimer(timeInterval: 20, target: self, selector: 
#selector(test(_:)), userInfo: nil, repeats: true)
}

@objc func test(_ timer: Timer) {

}
}

error: constant 'self.timer' used before being initialized
timer = Timer.scheduledTimer(timeInterval: 20, target: self, selector: 
#selector(test(_:)), userInfo: nil, repeats: true)

But this does:

class TestTwo {
var timer: Timer!

init() {
timer = Timer.scheduledTimer(timeInterval: 20, target: self, selector: 
#selector(test(_:)), userInfo: nil, repeats: true)
}

@objc func test(_ timer: Timer) {

}
}___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Using 'SomeProtocol' as a concrete type conforming to protocol 'SomeProtocol' is not supported

2016-12-28 Thread Brandon Knope via swift-users
Aren’t I losing the ability to enforce what is going into this enum’s 
associated value then?

Brandon

> On Dec 28, 2016, at 7:05 PM, Nevin Brackett-Rozinsky 
> <nevin.brackettrozin...@gmail.com> wrote:
> 
> It will work if you change the enum declaration to:
> 
> enum ElementNode
> 
> In other words, let the enum hold arbitrary unconstrained associated types, 
> and then make your APIs utilize instances of the enum with the associated 
> type constrained to a protocol.
> 
> The specific example you provide is essentially equivalent to:
> 
> var childElements = [Element?]()
> 
> Nevin
> 
> 
> On Wed, Dec 28, 2016 at 6:41 PM, Brandon Knope via swift-users 
> <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:
> I don’t understand why this is a problem
> 
> protocol Element {
> 
> }
> 
> enum ElementNode {
> case element(T)
> case empty
> }
> 
> var childElements = [ElementNode]()
> 
> I need to represent an array of my nodes that could be multiple kinds of 
> elements
> 
> Is there a workaround?
> 
> Brandon
> 
> ___
> swift-users mailing list
> swift-users@swift.org <mailto:swift-users@swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users 
> <https://lists.swift.org/mailman/listinfo/swift-users>
> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Using 'SomeProtocol' as a concrete type conforming to protocol 'SomeProtocol' is not supported

2016-12-28 Thread Brandon Knope via swift-users
I don’t understand why this is a problem

protocol Element {

}

enum ElementNode {
case element(T)
case empty
}

var childElements = [ElementNode]()

I need to represent an array of my nodes that could be multiple kinds of 
elements

Is there a workaround?

Brandon___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] swift-commits notifications mailing list no longer working

2016-11-29 Thread Brandon Knope via swift-users
The swift-commits archive is empty and I am no longer receiving email updates 
when a commit is made. 

Where is the best place to report or address this?

Thanks,
Brandon 
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] super.init() called automatically?

2016-05-16 Thread Brandon Knope via swift-users
I did not know of this behavior, but it looks like if the superclasses 
designated initializer is just a plain init() then it will automatically call 
super.init() from your subclass.

There is no way to avoid not calling your superclasses’s designated initializer 
and I guess the compiler ensures this by implicitly placing a call to super?

For example, if you change your Foo init to init(test:Int) { } then your 
subclass will complain that it’s not calling super’s designated initializer.

I have no idea why super can be implicitly called and I see no reference to 
this in the language guide.

I am not sure I like this behavior. It should either be documented (maybe I am 
missing it?) or requiring calling super explicitly.

Brandon

> On May 16, 2016, at 10:09 AM, tuuranton--- via swift-users 
>  wrote:
> 
> Why does the following code compile?
> Why does Bar's init(x: Int) automatically call Foo's init()?
> Why don't I have to manually call super.init() myself?
> 
> What passage of
> https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-ID203
>  
> 
> tells me that this should be the case?
> 
> 
> class Foo {
> init() {
> print("foo init")
> }
> }
> class Bar: Foo {
> init(x: Int) {
> print("bar init")
> }
> }
> let b = Bar(x: 0)
> //prints:
> //bar init
> //foo init
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users