[swift-users] struct property changing calls didSet of the Struct each time, but class won't

2017-11-13 Thread Zhao Xin via swift-users
Hi everyone, See below codes, //: Playground - noun: a place where people can play import Foundation struct Foo { var bar = 0 } class A { var foo = Foo() { didSet { print("foo changed") } } } let a = A() for i in 1...5 { a.foo.bar =

Re: [swift-users] Swift 4 "Cannot use mutating member on immutable value: 'self' is immutable"

2017-09-13 Thread Zhao Xin via swift-users
I begin to think it is related to how you `popFirst()` implemented. Check it or post it here. Zhao Xin On Thu, Sep 14, 2017 at 9:36 AM, Roderick Mann wrote: > Yeah, that's not it. I made the change you suggested, I get the same error. > > > On Sep 13, 2017, at 18:11 ,

Re: [swift-users] Foundation bug or indended?

2017-09-04 Thread Zhao Xin via swift-users
It is intended. The swift version you provided is the swift version of Objective-C header. So they are the same. Zhao Xin On Mon, Sep 4, 2017 at 8:01 PM, Adrian Zubarev via swift-users < swift-users@swift.org> wrote: > Hi there, > > before filing a new issue I would like to ask if this is

Re: [swift-users] Can't convert to the latest version of Swift because can't find framework module

2017-08-25 Thread Zhao Xin via swift-users
You said you used Xcode command. Did you mean the menu item in Xcode? If so, you should file a bug on Xcode on bugreport.apple.com. As far as I know, swift migration guide is planed to be open sourced, but it is not opened yet. So you should file a bug to Apple. Zhao Xin​ On Sat, Aug 26, 2017

Re: [swift-users] Simultaneous accesses, but modification requires exclusive access

2017-07-24 Thread Zhao Xin via swift-users
You can use serial queue. class Car { var helper = Helper() lazy private var queue = DispatchQueue(label: "my queue") func test() { helper.doSomething(f1: f1) } func f1() { queue.async { _ = self.helper.v1 //Crash - Simultaneous accesses

[swift-users] matching a protocol value in multiple patterns is not yet supported; use separate cases instead

2017-07-18 Thread Zhao Xin via swift-users
I encounter this error today. "matching a protocol value in multiple patterns is not yet supported; use separate cases instead" Sample code: import Foundation protocol NameProtocol { var name:String { get } } struct Cat:NameProtocol { let name:String } struct Dog:NameProtocol {

Re: [swift-users] Is there any harm that an @escaping handler never called?

2017-07-11 Thread Zhao Xin via swift-users
Glad to know the answer. And thank you, Slava and Daniel.​ Zhao Xin On Wed, Jul 12, 2017 at 7:53 AM, Daniel Dunbar <daniel_dun...@apple.com> wrote: > > On Jul 11, 2017, at 3:55 PM, Zhao Xin via swift-users < > swift-users@swift.org> wrote: > > For example, I

[swift-users] Is there any harm that an @escaping handler never called?

2017-07-11 Thread Zhao Xin via swift-users
For example, I have an async query, I pass it an `@escaping resultHandler`. If there is any results, the handler will run. However, if the result is empty, the `@escaping resultHandler` will never run. Is there any memory leak or something will happen if the `@escaping resultHandler` never runs?

Re: [swift-users] Should Array's `append(_)` function cause `didSet`?

2017-07-10 Thread Zhao Xin via swift-users
Thanks. Zhao Xin On Tue, Jul 11, 2017 at 2:29 AM, Jordan Rose wrote: > > > On Jul 7, 2017, at 22:50, Marco S Hyman via swift-users < > swift-users@swift.org> wrote: > > > On Jul 7, 2017, at 9:48 PM, Zhao Xin wrote: > > Thank you very much Marco. But

Re: [swift-users] Filling two type parameters with the same type

2017-07-09 Thread Zhao Xin via swift-users
Sorry Dave, I didn't notice that you said in `extension`. I just put the "where Source == Displacement" to the original poster's code and the error showed. My bad. Zhao Xin On Sun, Jul 9, 2017 at 1:56 PM, David Sweeris wrote: > Hmm... I just tried it in a playground, and

Re: [swift-users] Filling two type parameters with the same type

2017-07-08 Thread Zhao Xin via swift-users
typealias now = not. Zhao Xin On Sun, Jul 9, 2017 at 12:39 PM, Zhao Xin wrote: > No, David, it is now allowed. "error: same-type requirement makes generic > parameters 'Source' and 'Displacement' equivalent". > > Zhao Xin > > On Sun, Jul 9, 2017 at 12:35 PM, David Sweeris

Re: [swift-users] Filling two type parameters with the same type

2017-07-08 Thread Zhao Xin via swift-users
No, David, it is now allowed. "error: same-type requirement makes generic parameters 'Source' and 'Displacement' equivalent". Zhao Xin On Sun, Jul 9, 2017 at 12:35 PM, David Sweeris via swift-users < swift-users@swift.org> wrote: > You could try putting that init in an extension "where Source

Re: [swift-users] Filling two type parameters with the same type

2017-07-08 Thread Zhao Xin via swift-users
Please try this: struct DistortedNoise where Source:Noise { typealias Displacement = Source let source:Source let displacement:Displacement init(source:Source, displacement:Displacement) { self.source = source self.displacement = displacement

Re: [swift-users] Should Array's `append(_)` function cause `didSet`?

2017-07-07 Thread Zhao Xin via swift-users
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() }

Re: [swift-users] Should Array's `append(_)` function cause `didSet`?

2017-07-07 Thread Zhao Xin via swift-users
* *Target: x86_64-apple-macosx10.9* *macOS Sierra 10.12.5 (16F73)* Zhao Xin On Fri, Jul 7, 2017 at 11:52 PM, Jordan Rose <jordan_r...@apple.com> wrote: > It definitely should. Can you show the code where it wasn’t being called? > > Thanks! > Jordan > > > O

[swift-users] Should Array's `append(_)` function cause `didSet`?

2017-07-07 Thread Zhao Xin via swift-users
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

Re: [swift-users] Design guidelines for computed property vs no-arg method

2017-07-05 Thread Zhao Xin via swift-users
For me, a noun is a property, a verb is a method. So `foo` is a property, `calculateFoo()` is a method. For your specific question, `func signum() -> Self` returns `Self`, which can't be used in property. `var signum:Self { return self }` will generate an error "'Self' is only available in a

Re: [swift-users] can we express "does not conform to a particular protocol"?

2017-07-03 Thread Zhao Xin via swift-users
In my own test, it seams that there is no way to test a type conforms to Equatable or not. `Protocol 'Equatable' can only be used as a generic constraint because it has Self or associated type requirements` Zhao Xin On Tue, Jul 4, 2017 at 9:27 AM, David Baraff wrote: >

Re: [swift-users] can we express "does not conform to a particular protocol"?

2017-07-03 Thread Zhao Xin via swift-users
You mean `type(of:lhs) == type(of:rhs)`? Zhao Xin On Tue, Jul 4, 2017 at 8:00 AM, David Baraff via swift-users < swift-users@swift.org> wrote: > I’m searching for the simplest way to write a function > func maybeEqual(_ lhs:T, _rhs:T) -> Bool > > where it returns lhs == rhs if T is equatable,

Re: [swift-users] Covariance in Generic Protocols & Proposal 0142

2017-06-25 Thread Zhao Xin via swift-users
`protocol A: GenericProtocol where Instance == String { }` means, A is something that `Instance` must be `String`. However, it doesn't mean `Instance` has already been `String`. So without assigning your `Instance`, the compiler doesn't know the type of your `Instance`. Zhao Xin On Mon, Jun 26,

Re: [swift-users] Optional binding with non-optional expression

2017-06-04 Thread Zhao Xin via swift-users
Then I knew it. if let a: A = A() { // this is a warning as it treats like always true print("something") // this line always runs } For if let a = A() { // show an error as the compiler thinks you are missing something. } For me, the first example, explicitly given the type of `a`, so

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-04 Thread Zhao Xin via swift-users
Will this work? class TapGestureRecognizer: UITapGestureRecognizer { var onTap: (() -> Void)? init(onTap: (() -> Void)?) { self.onTap = onTap super.init(target: nil, action: nil) *self.removeTarget(nil, action: nil)* self.addTarget(self, action:

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-03 Thread Zhao Xin via swift-users
I was not talking about the formatting. I am talking about the implementation. You can't use `self` before you call `super.init` as you did now. If changing your implementation to called `super.init` and then call `self` in `super.init` again. You would have called `super.init` twice. I don't

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-03 Thread Zhao Xin via swift-users
You should change to another way. Using `self` in `super.init` is not allowed. Zhaoxin On Sun, Jun 4, 2017 at 12:38 PM, Geordie Jay wrote: > I am dealing with a variant of this on Android right now. I have just > subclassed e.g. UITapGestureRecognizer to perform the 2nd

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-02 Thread Zhao Xin via swift-users
I found two workarounds. 1. protocol Foo: class { func bar() } class Base:Foo { @objc func bar() { print("bar") } } class Baz: Base { override init() { super.init() let tapRecognizer = UITapGestureRecognizer(target: self, action:

Re: [swift-users] Optional binding with non-optional expression

2017-06-02 Thread Zhao Xin via swift-users
I think it did an unnecessary implicitly casting. For example, let y = Int(exactly: 5) print(type(of:y)) // Optional You code equals to if let y:Int = Int(exactly: 5) { } However, I don't know why it did that. Maybe because of type inferring? Zhaoxin On Fri, Jun 2, 2017 at 8:40 PM,

Re: [swift-users] Conforming to the protocol requirements with implicitly unwrapped optional

2017-05-29 Thread Zhao Xin via swift-users
You can try this. protocol Container : class { var component: Component { get } } class ConcreteContainer : Container { lazy var component: Component = { return Component(container: self) }() } class Component { unowned let container: Container init(container: Container)

Re: [swift-users] Conforming to the protocol requirements with implicitly unwrapped optional

2017-05-29 Thread Zhao Xin via swift-users
Why you have to use `unwrapped optional` at the first place? If you have to use it, it means it could be nil. So it won't conform the protocol, which requires the `value` never nil. Zhaoxin On Mon, May 29, 2017 at 12:37 PM, Anton Bronnikov via swift-users < swift-users@swift.org> wrote: > Hi

Re: [swift-users] Why inout protocol parameter in function work with strange

2017-05-27 Thread Zhao Xin via swift-users
Because generic uses `Car` instead of `Position` when running the code, so there is no casting as `car as Position` as in your original code. The `T:Position` part restricts that the type conforms `Position`, but it won't use `Position`, it uses the type. Zhaoxin On Sat, May 27, 2017 at 4:58 PM,

Re: [swift-users] NSDictionary passed through Swift loses access to category methods

2017-05-23 Thread Zhao Xin via swift-users
I don't think this is the good place for your question. Maybe stackoverflow or apple developer forum is more suitable. Did you added the header filename of the category to your bridge file? Also, is there the method name in the header file as well? You know, sometimes people wouldn't include the

Re: [swift-users] Swift localisation, percentage sign escaping

2017-05-11 Thread Zhao Xin via swift-users
Forgot to show an example. In Swift, below code won't work, let says = NSLocalizedString("It runs \(count) times", comment: "run times") You should use let says = String.localizedStringWithFormat(NSLocalizedString("It runs %@ times", comment: "run times"), String(count)) Zhaoxin On Fri, May

Re: [swift-users] Why is static a keyword?

2017-05-11 Thread Zhao Xin via swift-users
dartist.com> wrote: > >> I don’t think this is the answer that was asked for. I bet it’s more a >> technical question from the internal point of of view. >> >> >> -- >> Adrian Zubarev >> Sent with Airmail >> >> Am 11. Mai 2017 um 18:59

Re: [swift-users] Why is static a keyword?

2017-05-11 Thread Zhao Xin via swift-users
> -- > Adrian Zubarev > Sent with Airmail > > Am 11. Mai 2017 um 18:59:58, Zhao Xin via swift-users ( > swift-users@swift.org) schrieb: > > In Swift, you use `static in struct and enum` and `class in class`. For > example, > > struct Foo { > > static func bar(

Re: [swift-users] Why is static a keyword?

2017-05-11 Thread Zhao Xin via swift-users
In Swift, you use `static in struct and enum` and `class in class`. For example, struct Foo { static func bar() { } } class ClassFoo { class func bar() { } } Another the `class func bar()` can replace to `static` as well. Here the `static` and `class` are equal in

Re: [swift-users] Help! Slicing an array is very expensive

2017-05-08 Thread Zhao Xin via swift-users
Have you try other approaches? Maybe just write your data to cache on disk and read it back will be quicker? Zhaoxin On Tue, May 9, 2017 at 8:01 AM, Philippe Hausler via swift-users < swift-users@swift.org> wrote: > I wonder if Data might be a better tool for the job here since it is it’s > own

Re: [swift-users] optional variable with ternary operator

2017-05-08 Thread Zhao Xin via swift-users
I wonder if it has ever been allowed? I am using Xcode and it never allows that. For you specific question, you can use var number:Int? let result = (number ?? -1) > 0 ? 1 : 2 Zhaoxin On Tue, May 9, 2017 at 1:39 AM, Erica Sadun via swift-users < swift-users@swift.org> wrote: > I believe this

Re: [swift-users] Making Error sub-enums Equatable

2017-05-08 Thread Zhao Xin via swift-users
I think you'd better define your own operator, maybe `=~` or something else. As `==` has already meant something in enum. Zhaoxin On Mon, May 8, 2017 at 5:07 PM, Rien via swift-users wrote: > I’d love to know if there is a better way, but a ‘switch’ or 'if case' is > the

Re: [swift-users] Flatmap initializer inconsistency

2017-05-01 Thread Zhao Xin via swift-users
:20 AM, Saagar Jha <saa...@saagarjha.com> wrote: > Well, the question still remains about why the compiler chose > init(exactly:) over init(). Shouldn’t there at least a warning of ambiguity? > > Saagar Jha > > On May 1, 2017, at 12:11, Zhao Xin via swift-users <swift-us

Re: [swift-users] Flatmap initializer inconsistency

2017-05-01 Thread Zhao Xin via swift-users
In my test, compiler thought you use `init?(exactly value: Double)`, which returns nil. So this is not a bug. Zhaoxin On Tue, May 2, 2017 at 1:39 AM, Halen Wooten via swift-users < swift-users@swift.org> wrote: > Hi, > > I'm seeing a weird issue with using an initializer in flatMap. Here's > an

Re: [swift-users] weak self

2017-05-01 Thread Zhao Xin via swift-users
[weak self] and [unowned self] are used to solve the problem of Strong Reference Cycles Between Class Instances . If you can grantee self won't be nil during

Re: [swift-users] odd `==` `!=` behavior with class that inherits `NSObject`

2017-04-19 Thread Zhao Xin via swift-users
t;nbirkh...@gmail.com> >> wrote: >> >>> Your issue seems to be that you created a custom implementation for the >>> `==` operator but not one for the `!=` operator. If I add a custom >>> implementation for `!=` I get the results you expected.

Re: [swift-users] odd `==` `!=` behavior with class that inherits `NSObject`

2017-04-18 Thread Zhao Xin via swift-users
Everyone should notice that in the do-block (Sample 2). The result is just opposite of the code out of it (Sample 1). Or say, out the do-block, Swift calls `==` directly. In the do-block, Swift just call `isEqual(_)` instead of `==`. That is the inconsistency I am confused. Zhaoxin On Wed, Apr

[swift-users] odd `==` `!=` behavior with class that inherits `NSObject`

2017-04-18 Thread Zhao Xin via swift-users
Sample 1: both `==` and `!=` is true. import Foundation class Foo:NSObject { let name:String init(name:String) { self.name = name } public static func ==(lhs: Foo, rhs: Foo) -> Bool { guard type(of:lhs) == type(of:rhs) else { return false }

Re: [swift-users] Swift 3.1 String(

2017-04-05 Thread Zhao Xin via swift-users
I always use `NSLog("Update name for user %@", fbUser)`. Is `Log.info` your own implementation? Zhaoxin On Wed, Apr 5, 2017 at 10:26 PM, Maxim Veksler via swift-users < swift-users@swift.org> wrote: > Hi, > > Swift 3.1 compiler seems to introduces a new complier warning regarding >

Re: [swift-users] Protocol composition results in EXC_BAD_ACCESS

2017-04-03 Thread Zhao Xin via swift-users
Why not making State as a class? EffectiveState should be subclass of State. Zhaoxin On Mon, Apr 3, 2017 at 11:08 PM, Rudolf Adamkovič via swift-users < swift-users@swift.org> wrote: > On 3 Apr 2017, at 16:48, Adrian Zubarev > wrote: > > Why do you cast against

[swift-users] Set with element of NSObject subclasses didn't work as expected

2017-03-28 Thread Zhao Xin via swift-users
Please see the code first. import Foundation class Foo:Hashable { let value:Int public var hashValue: Int { return value } public static func ==(lhs: Foo, rhs: Foo) -> Bool { return lhs.value == rhs.value } init(_ value:Int) { self.value = value

Re: [swift-users] @noReturn

2017-03-24 Thread Zhao Xin via swift-users
Change you `func findReasonAndTerminate()` to `func findReasonAndTerminate() -> String`. Then you can use `fatalError(func findReasonAndTerminate())`. Zhaoxin On Fri, Mar 24, 2017 at 5:02 PM, Rien via swift-users wrote: > Is there any way to mark a function as “no

Re: [swift-users] Generic and Nested Types

2017-03-23 Thread Zhao Xin via swift-users
Which you? Zhaoxin On Thu, Mar 23, 2017 at 4:55 PM, Седых Александр via swift-users < swift-users@swift.org> wrote: > Hello. Please explain me, why we can't make Nested Types in Generic Types? > > > > -- > Седых Александр > > ___ > swift-users mailing

Re: [swift-users] How to pass a protocol as parameter, without using @objc?

2017-03-14 Thread Zhao Xin via swift-users
Great! Zhaoxin On Tue, Mar 14, 2017 at 2:15 PM, Bruno Macabeus via swift-users < swift-users@swift.org> wrote: > I found the solution. I need use a closure. > I updated the gist: https://gist.github.com/brunomacabeusbr/ > eea343bb9119b96eed3393e41dcda0c9 > > 2017-03-13 1:38 GMT-03:00 Bruno

Re: [swift-users] OptionSet as Sequence

2017-03-12 Thread Zhao Xin via swift-users
I don't see the needs to call `for domain in domains` with `domains:OptionSet`. If a parameter want an OptionSet, why not just use`domains` directly instead of `domain`? Zhaoxin On Mon, Mar 13, 2017 at 12:09 AM, J.E. Schotsman via swift-users < swift-users@swift.org> wrote: > Hello, > >

Re: [swift-users] Unexpected results when using String.CharacterView.Index

2017-03-09 Thread Zhao Xin via swift-users
Thanks a lot, Ole. I understand now. Zhaoxin On Thu, Mar 9, 2017 at 7:54 PM, Ole Begemann <o...@oleb.net> wrote: > On 09/03/2017 08:27, Zhao Xin via swift-users wrote: > >> When using subscript of `String.CharacterView`, I got an unexpected error. >> >> fatal

[swift-users] Unexpected results when using String.CharacterView.Index

2017-03-08 Thread Zhao Xin via swift-users
When using subscript of `String.CharacterView`, I got an unexpected error. fatal error: Can't form a Character from an empty String func test() { let s = "Original Script:" let cs = s.characters //let startIndex = cs.startIndex let nextIndex = "Original

Re: [swift-users] Is this really a race condition?

2017-03-02 Thread Zhao Xin via swift-users
I am sorry if this bothers you. I just put the original code in Xcode and it works. Anyone knows why this works in Xcode or in macOS? I thought it should show the same warnings as Linux. Zhaoxin On Fri, Mar 3, 2017 at 2:51 AM, Edward Connell via swift-users < swift-users@swift.org> wrote: > Hi

Re: [swift-users] unowned self in closure in a playground

2017-02-21 Thread Zhao Xin via swift-users
I think you are right on ` lifetime guaranteed to be around until the method call completes`. But`[unowned self]` released the retain manually in your code. Just removing `[unowned self]` part, you code will work. Zhaoxin On Wed, Feb 22, 2017 at 3:18 AM, Marco S Hyman via swift-users <

Re: [swift-users] ambiguous minus operator

2017-02-16 Thread Zhao Xin via swift-users
I don't know if you are using an IDE, but in Xcode. I can just cmd+mouse left click to see the code headers. Zhaoxin On Fri, Feb 17, 2017 at 2:22 AM, Jon Shier via swift-users < swift-users@swift.org> wrote: > I’ve had good luck with being able to click the candidates in > cases like

Re: [swift-users] [swift-evolution] for in? optionalCollection {

2017-02-11 Thread Zhao Xin via swift-users
What about just use test?.forEach { print($0) } Zhaoxin On Sat, Feb 11, 2017 at 7:48 PM, Tino Heth via swift-evolution < swift-evolut...@swift.org> wrote: > This one started over at swift-users, with a question on how to deal with > looping over containers that may be nil. > > Imho the beauty

Re: [swift-users] EnumerateUsingObjects in Swift

2017-01-25 Thread Zhao Xin via swift-users
Can you check the version of you Swift? Your code works in Xcode 8.2.1 (8C1002), Swift 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1) Zhaoxin On Thu, Jan 26, 2017 at 2:49 AM, Doug Hill wrote: > OK, I just tried testing this code in my app and a Swift playground. I > also

Re: [swift-users] EnumerateUsingObjects in Swift

2017-01-23 Thread Zhao Xin via swift-users
It seems to me that you didn't initialize your `myArray` before you casted it. That caused the problem. Zhaoxin On Tue, Jan 24, 2017 at 9:34 AM, Jon Shier via swift-users < swift-users@swift.org> wrote: > enumerateObjects(options:using:) exists on NSArray in Swift. And I was > able to create

Re: [swift-users] Protocol extension gotcha... or bug?

2017-01-23 Thread Zhao Xin via swift-users
Wagner, the `extension` of `protocol` is never dynamic. It is `fail safe`. It means if you don't implement something, the compiler will use the implementation in the `protocol extension`. As in swift, struct and enum can also conform protocols. If you want the other way, you should do it in a

Re: [swift-users] Compiler should issue a warning when a subclass implementation with default values matches a parent implementation without them

2017-01-23 Thread Zhao Xin via swift-users
I doubt if you could have done that in swift-evolution list. As for an evolution, it requests that you not only provides the question, but also must provide the answer and how to implementing in code together. Zhaoxin On Mon, Jan 23, 2017 at 6:04 PM, Wagner Truppel via swift-users <

Re: [swift-users] Bool type and reading and writing operation atomicity

2017-01-19 Thread Zhao Xin via swift-users
You can use the GCD semaphore. https://developer.apple.com/reference/dispatch/dispatchsemaphore Or it is always better to consider of using queues if you can.

Re: [swift-users] Strange Error about Default values

2017-01-18 Thread Zhao Xin via swift-users
Maybe what you want is struct S1 { private var _v = 1 var v:Int { get { return self._v } } } Zhaoxin On Thu, Jan 19, 2017 at 2:08 AM, Jordan Rose via swift-users < swift-users@swift.org> wrote: > It is a terrible error message, though. I've filed

Re: [swift-users] Weird protocol behaviour.

2016-12-23 Thread Zhao Xin via swift-users
My previous theory was wrong. > P is an existential for x: P = … where it is upgraded to the static P in foo Why it needs to be upgraded? Why not just use `P` as a protocol instead of a `type`? Xcode error message calls `P` as a type. Zhaoxin On Fri, Dec 23, 2016 at 9:03 PM, Adrian Zubarev <

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Zhao Xin via swift-users
Below code should work: let blockSize = min(512, count) let blockCount = (count+blockSize-1)/blockSize let boxedClosure = { (foo:inout MutableDeviceCollection) -> () in device.sync { // Launch CUDA kernel try! fill<<<(blockSize, blockCount)>>>[

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Zhao Xin via swift-users
What is the type of self? If it is a class, try [unowned self]. Zhaoxin On Fri, Dec 16, 2016 at 4:33 PM, Rien via swift-users wrote: > How about using: > > UnsafeMutablePointer > > ? > > Regards, > Rien > > Site: http://balancingrock.nl > Blog:

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Zhao Xin via swift-users
I did not test the code. But if you cannot implicitly capture a mutating self, you should do it explicitly, right? let blockSize = min(512, count) let blockCount = (count+blockSize-1)/blockSize device.sync { *[self] () -> () in* // Launch CUDA kernel try! fill<<<(blockSize, blockCount)>>>[

Re: [swift-users] Binary package dependencies

2016-12-02 Thread Zhao Xin via swift-users
You are not wrong and it is on schedule of Swift 4. Zhaoxin On Fri, Dec 2, 2016 at 4:05 PM, Georgios Moschovitis via swift-users < swift-users@swift.org> wrote: > Hi, > > It would be great to be able to depend on 'binary' (i.e. precompiled) > modules/packages using SPM. This would allow

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Zhao Xin via swift-users
protocol Copyable { func copy() -> Self } final class Storage:Copyable { var keys: [String] = [] var values: [Int] = [] func copy() -> Storage { let s = Storage() s.keys = keys s.values = values return s } } public struct

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Zhao Xin via swift-users
>Why is the second check false, even if the property is marked as unowned for the view? Please search the mailing list, this is not the first time it comes as a new question. Shortly speaking, it is `false` only because you used `unowned`. If you you can grantee it always exists. Just use it

Re: [swift-users] minimum deployment target

2016-11-14 Thread Zhao Xin via swift-users
Maybe you should ask this question in https://forums.developer.apple.com/welcome Zhaoxin On Mon, Nov 14, 2016 at 6:26 PM, J.E. Schotsman via swift-users < swift-users@swift.org> wrote: > Hello, > > I have some code that is used in both a project with minimum deployment > target 10.9 and a

Re: [swift-users] if-case syntax ambiguity

2016-11-09 Thread Zhao Xin via swift-users
The `if case` is the same meaning as `switch-case`, so I don't think there is anything ambitious. For `switch-case`, it is not equal, it is matching. Zhaoxin On Wed, Nov 9, 2016 at 7:17 PM, Nicholas Outram via swift-users < swift-users@swift.org> wrote: > Hi > > I’ve been drilling down on the

Re: [swift-users] Localization in Swift.

2016-11-03 Thread Zhao Xin via swift-users
I just uploaded this as a Xcode extension. You can download it here . As long as Swift is not supporting this, you can use my Xcode extension. Zhaoxin On Thu, Nov 3, 2016 at 10:36 AM, Zhao Xin wrote: > Hello everyone. Thanks to

Re: [swift-users] Localization in Swift.

2016-11-02 Thread Zhao Xin via swift-users
Hello everyone. Thanks to you all for replies in this thread. I am currently working on a Xcode Extension for this purpose. I would like to bring it to github in this week. This will be my first Xcode extension, also my first github open sourced project. Zhaoxin On Thu, Nov 3, 2016 at 6:14 AM,

Re: [swift-users] Localization in Swift.

2016-11-01 Thread Zhao Xin via swift-users
I am not talking to eliminate "%" style function. I am talking to add more compatibility to `NSLocalizedString` with `\(foo)` style. As there is no rule forbidding that, it should work. If someone doesn't need the flexible parts, why he has to use the complicated way? Zhaoxin On Wed, Nov 2, 2016

Re: [swift-users] Localization in Swift.

2016-11-01 Thread Zhao Xin via swift-users
ry localized string that is with '\(foo)' in `NSLocalizedString` and > converted to `String.localizedStringWithFormat(NSLocalizedString...` > internally. > > Zhaoxin > > > On Wed, Nov 2, 2016 at 12:08 AM, Jens Alfke <j...@mooseyard.com> wrote: > >> >> > On N

[swift-users] Localization in Swift.

2016-11-01 Thread Zhao Xin via swift-users
I encountered a localization problem today. At first I translated a string like this. let count = 10 > let says = NSLocalizedString("It runs \(count) times", comment: "run > times") I couldn't get the translation taking effect. So I open the setting "Localization Debugging" in scheme and get

Re: [swift-users] Will it be better if `fallthrough` works with `label` in nested `switch - case`?

2016-10-14 Thread Zhao Xin via swift-users
I manage to use below work around. let count = 1 switch count { case 0, 1: let buttonId = NSAlertThirdButtonReturn let shouldFallthrough = { () -> Bool in switch buttonId { case NSAlertFirstButtonReturn: print("do something") case

[swift-users] Will it be better if `fallthrough` works with `label` in nested `switch - case`?

2016-10-14 Thread Zhao Xin via swift-users
I thought below code would work. It didn't. let count = 1 outerSwitch: switch count { case 0, 1: let buttonId = 0 switch buttonId { case NSAlertFirstButtonReturn: print("do something") case NSAlertSecondButtonReturn: print("do something") case

[swift-users] Why can't we get `URL` equal on the same path?

2016-10-14 Thread Zhao Xin via swift-users
As you can see, `URL` is not equal but the `path` is. I wonder why urls do not equal here? let url = URL(fileURLWithPath: "foo/bar", isDirectory: false) let baseURL = url.deletingLastPathComponent() let newURL = URL(fileURLWithPath: "bar", isDirectory: false, relativeTo: baseURL) print(url ==

Re: [swift-users] Compiler refuses non-escaping closure calls in nested function

2016-10-10 Thread Zhao Xin via swift-users
Thank you, Ole. Your reply teaches me a lot. Zhaoxin On Mon, Oct 10, 2016 at 6:52 PM, Ole Begemann via swift-users < swift-users@swift.org> wrote: > The line "let result = closure(n)" is refused by the compiler with the >> error message "declaration over non closing parameter may allow it to >>

Re: [swift-users] Compiler refuses non-escaping closure calls in nested function: Bug?

2016-10-10 Thread Zhao Xin via swift-users
> It is just like there were two ways to do the job, you thought it worked in this way, but it chose the other way. Both ways lead to the same result. I think it is because the compiler **flatten** your inner function instead of calculated the result. The variable scope of `closure` is outside

[swift-users] Is there an equivalence method on `NSArray`'s `func objects(at indexes: IndexSet) -> [Any]` in Array?

2016-10-06 Thread Zhao Xin via swift-users
I managed to do that by using `map` as I didn't find the equivalence. files.forEach { var indices = IndexSet() for index in 0 ..< subtitleFiles.count { if $0.sn == subtitleFiles[index].sn { indices.insert(index) } } let subtitles =

Re: [swift-users] Any?

2016-09-27 Thread Zhao Xin via swift-users
`Any` is different from `Any?`. For example, if `Any` is an `Optional`, `Any?` is an `Optional`. I ​n you code, since ​`dictionary` subscripts may `return nil`, the `?` is for that. The `Any` is for the type of the `none-nil return value`. Zhaoxin On Tue, Sep 27, 2016 at 6:43 PM,

Re: [swift-users] Can anyone please explain this behavior?

2016-09-21 Thread Zhao Xin via swift-users
I suggest you defining the variables before using them like Marco does. Although from the global variable point of view, both way should be fine. But the glitch does exist, especially in playground. Zhaoxin On Thu, Sep 22, 2016 at 5:59 AM, Marco S Hyman via swift-users < swift-users@swift.org>

Re: [swift-users] reading keyboard input from xcode playgroud

2016-09-20 Thread Zhao Xin via swift-users
I test you code in command line `swiftc main.swift` and in macOS Command Line Tool app. Here is the main.swift: import Foundation import Foundation func input() -> String { let keyboard = FileHandle.standardInput let inputData = keyboard.availableData let strData =

[swift-users] [swift-user]Unexpected behavior of protocol extension.

2016-09-19 Thread Zhao Xin via swift-users
See below code. protocol Foo { func bar() } extension Foo { func bar() { print("I am bar.") } } class A:Foo { func output() { print(type(of:self)) // prints "B". self.bar() // prints "I am bar." (self as! B).bar() // prints "I am B."

Re: [swift-users] Stored Property on Protocol Extension

2016-09-12 Thread Zhao Xin via swift-users
​I don't know why the limit exists. Technical or on purpose. I hope someone inside can answer this. Zhaoxin​ On Mon, Sep 12, 2016 at 11:55 PM, Daniel Dunbar via swift-users < swift-users@swift.org> wrote: > > > On Sep 11, 2016, at 6:12 PM, Tanner Nelson via swift-users < >

Re: [swift-users] Lazy expression is ambiguous?

2016-09-12 Thread Zhao Xin via swift-users
It is not a bug. You must explicitly specify the variable's type if you use `lazy` keyword. `lazy` means the variable will be initialized later, but the compiler needs its type right now. Zhaoxin On Mon, Sep 12, 2016 at 3:02 PM, Quinn "The Eskimo!" via swift-users < swift-users@swift.org> wrote:

Re: [swift-users] Migrating to Swift 3 using Xcode fails

2016-09-08 Thread Zhao Xin via swift-users
I ​ am confused with your situation. You said, "I’ve migrated one of my projects to Swift 3 previously, with an earlier beta of Xcode.". Then in Xcode should not using Swift 2.3. Assuming ​X ​code using 2.3 wrongly, you should use Xcode migration tool again, after that Xcode will use Swift 3.0.

Re: [swift-users] Swift Playgrounds Not Included with iiOS 10.0.1 GM

2016-09-08 Thread Zhao Xin via swift-users
It is not on mine after upgrading to GM through OTA. Mine free space is 9.35GB. I think it can be easily explained. It is not a system app, it appeared in beta just because it is easily for us to test. It will appear in App Store when iOS 10 officially released. Zhaoxin On Fri, Sep 9, 2016 at

Re: [swift-users] 'Error' is ambiguous for type lookup in this context

2016-09-07 Thread Zhao Xin via swift-users
RealmSwift should likely consider changing their enum cases to >>> use lowerCamelCase like Swift 3 did. Also at some point it should consider >>> the changes to NSError / Swift.Error bridging. >>> >>> -Shawn >>> >>> On Wed, Sep 7, 2016 at 7:1

Re: [swift-users] 'Error' is ambiguous for type lookup in this context

2016-09-07 Thread Zhao Xin via swift-users
t; On Wed, Sep 7, 2016 at 7:18 PM Zhao Xin via swift-users < > swift-users@swift.org> wrote: > >> When I use RealmSwift in my project, I got an alert " 'Error' is >> ambiguous for type lookup in this context". >> >> import UIKit >> >

[swift-users] 'Error' is ambiguous for type lookup in this context

2016-09-07 Thread Zhao Xin via swift-users
When I use RealmSwift in my project, I got an alert " 'Error' is ambiguous for type lookup in this context". import UIKit import UserNotifications import WatchConnectivity import RealmSwift extension AppDelegate:WCSessionDelegate { func session(_ session: WCSession,

Re: [swift-users] Pass Value of Variable to a Function

2016-09-07 Thread Zhao Xin via swift-users
Now I understand your point. But as Jens said, Swift is a static language, it won't interpret `property` as a variable after `.`(dot). So for Swift compiler, you just refer to a none-exist property. Zhaoxin On Wed, Sep 7, 2016 at 12:39 PM, Michael Sheaver wrote: > Hi Zhao, > >

Re: [swift-users] Pass Value of Variable to a Function

2016-09-06 Thread Zhao Xin via swift-users
I think you messed up with `Locale` and `NSLocale`. `Locale` is a struct in Swift 3 to replace the legacy `NSLocale`. The latter is a class, it has an inner `structure` called `NSLocale.Key`. For `Locale`, there is no `NSLocale.Key`. All there keys are instance properties in `Locale`. So in your

Re: [swift-users] Can we `override var hashValue`?

2016-09-06 Thread Zhao Xin via swift-users
Thanks Lou. In addition to what Jordan and Dmitri have said, I think part of the > confusion is that you are assuming hash values are implicitly used in an > equality check. They are not. They are used when your instances are added > to certain types of collections. ​You are very nice. But I

Re: [swift-users] strange property observer behavior

2016-09-04 Thread Zhao Xin via swift-users
> > 1) when `didSet` observer will call? ​For me, it is more like Swift developer tries to override some beginner's flaw. ​2) infinite loop ​If you intended to do things bad, things ​went bad. 3) override property observer ​You mentioned "TSPL(The Swift Programming Language) ​", and it

Re: [swift-users] Subtract a set of a subclass?

2016-09-02 Thread Zhao Xin via swift-users
subclass to superclass as I did in previous replies. Zhaoxin On Sat, Sep 3, 2016 at 10:12 AM, Dmitri Gribenko <griboz...@gmail.com> wrote: > On Sat, Sep 3, 2016 at 4:47 AM, Zhao Xin via swift-users > <swift-users@swift.org> wrote: > > Hi Jordan, > > > > Both you an

Re: [swift-users] Subtract a set of a subclass?

2016-09-02 Thread Zhao Xin via swift-users
>> >> On Fri, Sep 2, 2016 at 7:02 AM, Nick Brook <nrbr...@gmail.com> wrote: >> >>> Hi Jordan, >>> >>> Thanks for the advice. >>> >>> What if a subclass does implement hashValue differently? It seems you >>> are saying a subcl

Re: [swift-users] Can we `override var hashValue`?

2016-09-02 Thread Zhao Xin via swift-users
ruit` version of > `hashValue`* could guarantee the `hashValue` equality, isn't that enough? > > Zhaoxin > > > On Sat, Sep 3, 2016 at 7:02 AM, Dmitri Gribenko <griboz...@gmail.com> > wrote: > >> On Sat, Sep 3, 2016 at 1:31 AM, Zhao Xin via swift-users >> <swif

  1   2   >