Re: [swift-users] SwiftPM on Linux Failed

2017-08-30 Thread adelzhang via swift-users

It seems like the only way is upgrading to Ubuntu 16.04 for now?

在 Wed, 30 Aug 2017 18:09:53 +0800,Ankit Aggarwal  
 写道:


Thanks for the detailed info. I was able to reproduce this. There seems  
to be some problem with importing modules without their swiftdoc in  
Ubuntu 14.04. I've filed https://bugs.swift.org/browse/SR-5800



On 30-Aug-2017, at 1:26 PM, adelzh...@qq.com wrote:

export SWIFT_HOME=/opt/swift/4.0-dev
export PATH="$SWIFT_HOME/usr/bin":"${PATH}"



--
Ankit




--
Regards

--adel


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


Re: [swift-users] SwiftPM on Linux Failed

2017-08-30 Thread adelzhang via swift-users

Hi,

`swift build -v` output:

lsb_release -r
clang --version
which clang
/opt/swift/4.0-dev/usr/bin/swiftc --driver-mode=swift -L  
/opt/swift/4.0-dev/usr/lib/swift/pm/4 -lPackageDescription -swift-version  
4 -I /opt/swift/4.0-dev/usr/lib/swift/pm/4 -sdk /  
/home/vagrant/hello/Package.swift -fileno 5

error: manifest parse error(s):
/home/vagrant/hello/Package.swift:4:8: error:  no such module  
'PackageDescription'

import PackageDescription
   ^
`opt/swift/4.0-dev/usr/lib/swift/pm/4` directory has two files,  
libPackageDescription.so and PackageDescription.swiftmodule


The steps I have took:

1) [Success] Install dependencies , download swift binary release and  
verify thhe PGP signature.

`$ sudo apt-get install clang libicu-dev`

2) [Success] Extract the archive and add swift path to PATH in `.bashrc`
```
export SWIFT_HOME=/opt/swift/4.0-dev
export PATH="$SWIFT_HOME/usr/bin":"${PATH}"
```

3) [Failed][Solved] Try using the REPL, enter the expression 1 + 1
maybe encounter https://bugs.swift.org/browse/SR-2783, fixed by change  
permissions of CoreFoundation headers


4) [Failed][Solved] Try using the REPL, import Glibc
maybe encounter https://bugs.swift.org/browse/SR-5524, fixed by setting  
C_INCLUDE_PATH and CPLUS_INCLUDE_PATH


5) [Failed][Solved] `swift build` said clang version is too low
Add ppa http://apt.llvm.org/

```
sudo apt-get upgrade clang
```

And now
```
$ clang --version
clang --version
clang version 6.0.0-svn311088-1~exp1 (trunk)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```

6) [Failed][no clue] `swift build` output no such module  
'PackageDescription'



在 Wed, 30 Aug 2017 01:59:39 +0800,Ankit Aggarwal  
 写道:



Hey,

Can you post the steps you followed to install the Swift toolchain?

Also, can you post the output of:
$ swift build -v

Thanks!

On Tue, Aug 29, 2017 at 8:14 PM, adelzhang via swift-users <
swift-users@swift.org> wrote:



Hi, everyone.

Installing swift on linux is not that easy. Following
https://swift.org/getting-started/#using-the-package-manager  
instruction,

but `swift build` failed:

```
error: manifest parse error(s):
/home/vagrant/hello/Package.swift:4:8: error: no such module
'PackageDescription'
import PackageDescription
   ^
```

I installed Swift 4.0

```
$swift version
Swift version 4.0-dev (LLVM 2dedb62a0b, Clang b9d76a314c, Swift  
0899bd328a)

Target: x86_64-unknown-linux-gnu
```

Ubuntu 14.04 is running on VirtualBox using vagrant.

```
$lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:Ubuntu 14.04.5 LTS
Release:14.04
Codename:   trusty
```

Does someone happen to know the work-around?

--
Regards

adelzhang


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




--
Regards

--adel


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


[swift-users] SwiftPM on Linux Failed

2017-08-29 Thread adelzhang via swift-users


Hi, everyone.

Installing swift on linux is not that easy. Following  
https://swift.org/getting-started/#using-the-package-manager instruction,  
but `swift build` failed:


```
error: manifest parse error(s):
/home/vagrant/hello/Package.swift:4:8: error: no such module  
'PackageDescription'

import PackageDescription
   ^
```

I installed Swift 4.0

```
$swift version
Swift version 4.0-dev (LLVM 2dedb62a0b, Clang b9d76a314c, Swift 0899bd328a)
Target: x86_64-unknown-linux-gnu
```

Ubuntu 14.04 is running on VirtualBox using vagrant.

```
$lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:Ubuntu 14.04.5 LTS
Release:14.04
Codename:   trusty
```

Does someone happen to know the work-around?

--
Regards

adelzhang


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


[swift-users] protocol where clause problem

2017-01-11 Thread adelzhang via swift-users

hello all!

I'm wondering if somebody can explain following snippet to me.

protocol P {
associatedtype Element
func next() -> Element
}

protocol Q {
associatedtype T : P
func makeT() -> T
}

extension Q where Self.T == Self {
func makeT() -> Self {
return self
}
}

// Why class A conform to protocol Q successfully?
class A: Q, P {
func next() -> Int {
return 0
}
}

`class A` does not declare associated type `T` explicitly. Why where  
clause check is passed ?



---
Regards

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


Re: [swift-users] strange property observer behavior

2016-09-04 Thread adelzhang via swift-users

Hi,

The following code works fine. The property `a` is stored twice. But
it don't enter infinite loop.

class Foo {
var a: Int = 0 {
 didSet {
 a = a + 1
 }
}
}

let foo = Foo()
foo.a = 2
print(foo.a) // output 3


Regards

--adel


在 Mon, 05 Sep 2016 00:27:16 +0800,Gerard Iglesias  
 写道:



Hi,

didSet is called as soon as the property is stored… Excepted when the  
value is stored in the initialiser code.


For me it is completely predictable that your code enter an infinite loop

Regards


On 4 Sep 2016, at 17:11, adelzhang via swift-users  
 wrote:


Thanks for reply.

How does Swift choose *rules* as you said?

Swfit encourage to override the property observer. But when we change  
the own property in Child class's `didSet` observer, that would cause  
infinite loop:


class Base {
var a: Int = 0
}

class Child : Base {
override var a: Int {
didSet {
 a = a + 1
}
}
 }

 let child = Child()
 child.a = 3

Any differcen with situation 1?





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


Re: [swift-users] strange property observer behavior

2016-09-04 Thread adelzhang via swift-users

Thanks for reply.

How does Swift choose *rules* as you said?

Swfit encourage to override the property observer. But when we change the  
own property in Child class's `didSet` observer, that would cause infinite  
loop:


class Base {
var a: Int = 0
}

class Child : Base {
override var a: Int {
didSet {
 a = a + 1
}
}
 }

 let child = Child()
 child.a = 3

Any differcen with situation 1?


在 Sun, 04 Sep 2016 20:12:42 +0800,Zhao Xin  写道:


1) when `didSet` observer will call?


​For me, it is more like Swift developer tries to override some  
beginner's flaw.


Above is incorrect. You can change property's value in `didSet`, that  
won't cause didSet called again as it is intended to give you the  
opportunity to do that.

​2) infinite loop


This can't apply the above rule as they set each other, causing the  
infinite loops.

Zhaoxin


On Sun, Sep 4, 2016 at 7:41 PM, Zhao Xin  wrote:

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 says in  
it:


“NOTE

The willSet and didSet observers of superclass properties are called  
when a property is set in a subclass initializer, after the superclass  
initializer has been called. They >are not called while a class is  
setting its own properties, before the superclass initializer has been  
called.


For more information about initializer delegation, see Initializer  
Delegation for Value Types and Initializer Delegation for Class Types.”


From: Apple Inc. “The Swift Programming Language (Swift 3 Beta)”。  
iBooks. https://itun.es/us/k5SW7.l


You didn't provide a `init()`, but since you properties were already  
set. There was a hidden `init()` when you called `Child()`.


Last,

let base = child as Base

base.a  = 4 // still output "base didset" and "child didset"

In Swift, as or as! won't change the instance's dynamic type. So it  
does nothing. `type(of:base)` is still `Child`.


Zhaoxin



On Sun, Sep 4, 2016 at 6:25 PM, adelzhang via swift-users  
 wrote:

Hi all

It sounds convenient to monitor change in property's value using  
property observer.
But TSPL(The Swift Programming Language) talk little about property  
observer. There

are some questions abouts property observer.

1) when `didSet` observer will call?

I assume it's fine that changing property's value in `didSet` observer.

   class Foo {
   var a: Int = 0 {
   didSet {
   print("didset")
   a = a + 1
   }
   }
   }

   let foo = Foo()
   foo.a = 4  // only output "didset" once

Why it don't cause infinite loop?

2) infinite loop

   // this code snippet cause inifinite loop
   class Foo {
   var a: Int = 0 {
   didSet {
   b = a + 1
   }
   }

   var b: Int = 1 {
   didSet {
   a = b - 1
   }
   }
   }

   let foo = Foo()
   foo.a = 2

3) override property observer

   class Base {
   var a: Int = 0 {
   didSet {
   print("base didset")
   }
   }
   }

   class Child : Base {
   override var a : Int {
   didSet {
   print("child didset")
   }
   }
   }

   let child = Child()
   child.a = 2 // output "base didset" and "child didset"
   let base = child as Base
   base.a  = 4 // still output "base didset" and "child didset"

Why overriding property observer still call parent's `didSet` observer?

--
Adel


___
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


[swift-users] strange property observer behavior

2016-09-04 Thread adelzhang via swift-users

Hi all

It sounds convenient to monitor change in property's value using property  
observer.
But TSPL(The Swift Programming Language) talk little about property  
observer. There

are some questions abouts property observer.

1) when `didSet` observer will call?

I assume it's fine that changing property's value in `didSet` observer.

class Foo {
var a: Int = 0 {
didSet {
print("didset")
a = a + 1
}
}
}

let foo = Foo()
foo.a = 4  // only output "didset" once

Why it don't cause infinite loop?

2) infinite loop

// this code snippet cause inifinite loop
class Foo {
var a: Int = 0 {
didSet {
b = a + 1
}
}

var b: Int = 1 {
didSet {
a = b - 1
}
}
}

let foo = Foo()
foo.a = 2

3) override property observer

class Base {
var a: Int = 0 {
didSet {
print("base didset")
}
}
}

class Child : Base {
override var a : Int {
didSet {
print("child didset")
}
}
}

let child = Child()
child.a = 2 // output "base didset" and "child didset"
let base = child as Base
base.a  = 4 // still output "base didset" and "child didset"

Why overriding property observer still call parent's `didSet` observer?

--
Adel


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


[swift-users] Implicitly type conversion ?

2016-08-18 Thread adelzhang via swift-users


I am confused by the code snippet following:

func foo(_ value: Int?) {
// do nothing
}

let a: Int = 2
foo(a) //  it works!


Why swift don't warn the type mismatch? I am woking on Xcode Version 7.3.1.


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