[swift-users] Confused by this error message

2017-01-30 Thread Travis Griggs via swift-users
I’m currently refactoring some code (Swift 3.?, latest XCode), and I ended up 
with the following:

func spansTSON() -> TSON {
var docs = self.spans.map() { $0.tson }
for (span, doc) in zip(self.spans, docs) {
if let datum = span.begin.datum {
if let index = self.spans.index(where: {return 
$0.includesAnchor(datum)}) {
doc["datum"] = (index * 2 + 
(datum.isBegin ? 0 : 1)).tson
}
}
}
return TSON.array(docs)
}

The vague error I get is “Ambiguous reference to spans” on the “if let index = 
self.spans…” line with the “self” highlighted. The container is a class. 
“spans” is computed property. I’m not sure if it’s confused about what self is, 
or spans. Or why either wouldn’t be clear.
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Confused by this error message

2017-01-30 Thread Travis Griggs via swift-users

> On Jan 30, 2017, at 3:19 PM, Travis Griggs  wrote:
> 
> I’m currently refactoring some code (Swift 3.?, latest XCode), and I ended up 
> with the following:
> 
>   func spansTSON() -> TSON {
>   var docs = self.spans.map() { $0.tson }
>   for (span, doc) in zip(self.spans, docs) {
>   if let datum = span.begin.datum {
>   if let index = self.spans.index(where: {return 
> $0.includesAnchor(datum)}) {
>   doc["datum"] = (index * 2 + 
> (datum.isBegin ? 0 : 1)).tson
>   }
>   }
>   }
>   return TSON.array(docs)
>   }
> 
> The vague error I get is “Ambiguous reference to spans” on the “if let index 
> = self.spans…” line with the “self” highlighted. The container is a class. 
> “spans” is computed property. I’m not sure if it’s confused about what self 
> is, or spans. Or why either wouldn’t be clear.

Nevermind.

I had a few moments before added a setter function that looked like func 
spans(tson:TSON)


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


Re: [swift-users] Importing Foundation or Glibc in REPL on Ubuntu 16.10 failing

2017-01-30 Thread Michael Gottesman via swift-users
Hmm... this sounds like this may be a good integration test. I am not sure what 
is going on here though. If I have a moment I will take a look a bit later 
today.

Michael

> On Jan 28, 2017, at 1:22 PM, Peter Ronnquist via swift-users 
>  wrote:
> 
> I have the same problem with importing Glibc into the REPL with "Swift
> 3.1 Development", Ubuntu 16.10, Jan 22, 2017, that was reported on the
> snapshot from 15 December (see below).
> 
> Is this working for anyone?
> 
> Best Regards
> Peter Ronnquist
> 
> 
> 
> 
> 
> On Monday 19 December Chris Double wrote:
> 
> 
> 
> Using the Ubuntu 16.10 snapshot from 15 December (or a build from
> master) I can't seem to get "import Foundation" or "import Glibc"
> working in the REPL. Here's an example:
> 
> -8<--
> $ swift
> Welcome to Swift version 3.1-dev (LLVM 7d4a331ed3, Clang d8c33dc710,
> Swift 2ea7951d05). Type :help for assistance.
>  1> import Glibc
> :3:10: note: in file included from :3:
> #include "///usr/include/utmp.h"
> ^
> 
> ///usr/include/utmp.h:23:10: note: in file included from
> ///usr/include/utmp.h:23:
> #include 
> ^
> 
> error: /usr/include/x86_64-linux-gnu/sys/types.h:146:10: error:
> 'stddef.h' file not found
> #include 
> ^
> 
> error: could not build Objective-C module 'SwiftGlibc'
> -8<--
> 
> 
> This works fine if I use 'swiftc' and compile a file:
> 
> $ cat x.swift
> import Glibc
> 
> print(random())
> 
> $ swiftc x.swift
> $ ./x
> ...
> -8<--
> 
> If I explicitly pass include paths to 'swift' it works in the REPL:
> 
> -8<--
> $ swift -I/home/user/swift-install/usr/lib/swift/clang/include/
> -I/home/user/swift-install/usr/include/lldb/Symbol/
> Welcome to Swift version 3.1-dev (LLVM 7d4a331ed3, Clang d8c33dc710,
> Swift 2ea7951d05). Type :help for assistance.
>  1> import Glibc
>  2> random()
> $R0: Int = 1804289383
> -8<--
> 
> Is there some setting or installation setup step I'm missing?
> 
> -- 
> http://bluishcoder.co.nz
> ___
> 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] Importing Foundation or Glibc in REPL on Ubuntu 16.10 failing

2017-01-30 Thread Peter Ronnquist via swift-users
I have the same problem with importing Glibc into the REPL with "Swift
3.1 Development", Ubuntu 16.10, Jan 22, 2017, that was reported on the
snapshot from 15 December (see below).

Is this working for anyone?

Best Regards
Peter Ronnquist





On Monday 19 December Chris Double wrote:



Using the Ubuntu 16.10 snapshot from 15 December (or a build from
master) I can't seem to get "import Foundation" or "import Glibc"
working in the REPL. Here's an example:

-8<--
$ swift
Welcome to Swift version 3.1-dev (LLVM 7d4a331ed3, Clang d8c33dc710,
Swift 2ea7951d05). Type :help for assistance.
  1> import Glibc
:3:10: note: in file included from :3:
#include "///usr/include/utmp.h"
 ^

///usr/include/utmp.h:23:10: note: in file included from
///usr/include/utmp.h:23:
#include 
 ^

error: /usr/include/x86_64-linux-gnu/sys/types.h:146:10: error:
'stddef.h' file not found
#include 
 ^

error: could not build Objective-C module 'SwiftGlibc'
-8<--


This works fine if I use 'swiftc' and compile a file:

$ cat x.swift
import Glibc

print(random())

$ swiftc x.swift
$ ./x
...
-8<--

If I explicitly pass include paths to 'swift' it works in the REPL:

-8<--
$ swift -I/home/user/swift-install/usr/lib/swift/clang/include/
-I/home/user/swift-install/usr/include/lldb/Symbol/
Welcome to Swift version 3.1-dev (LLVM 7d4a331ed3, Clang d8c33dc710,
Swift 2ea7951d05). Type :help for assistance.
  1> import Glibc
  2> random()
$R0: Int = 1804289383
-8<--

Is there some setting or installation setup step I'm missing?

-- 
http://bluishcoder.co.nz
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Importing Foundation or Glibc in REPL on Ubuntu 16.10 failing

2017-01-30 Thread Michael Gottesman via swift-users
Peter, what are you doing specifically. I.e. are you passing any arguments to 
swift or something like that? Can you give a full reproducer?

Also can you type swift -v to confirm the version #?

Michael

> On Jan 30, 2017, at 12:04 PM, Michael Gottesman via swift-users 
>  wrote:
> 
> Interesting... it looks like we /do/ have an integration test that imports 
> glibc into the repl:
> 
> https://github.com/apple/swift-integration-tests/blob/master/repl/test-repl-glibc.py
>  
> 
> 
> Probably could use one that imports Foundation though.
> 
> Michael
> 
> 
>> On Jan 30, 2017, at 12:00 PM, Michael Gottesman > > wrote:
>> 
>> Hmm... this sounds like this may be a good integration test. I am not sure 
>> what is going on here though. If I have a moment I will take a look a bit 
>> later today.
>> 
>> Michael
>> 
>>> On Jan 28, 2017, at 1:22 PM, Peter Ronnquist via swift-users 
>>> > wrote:
>>> 
>>> I have the same problem with importing Glibc into the REPL with "Swift
>>> 3.1 Development", Ubuntu 16.10, Jan 22, 2017, that was reported on the
>>> snapshot from 15 December (see below).
>>> 
>>> Is this working for anyone?
>>> 
>>> Best Regards
>>> Peter Ronnquist
>>> 
>>> 
>>> 
>>> 
>>> 
>>> On Monday 19 December Chris Double wrote:
>>> 
>>> 
>>> 
>>> Using the Ubuntu 16.10 snapshot from 15 December (or a build from
>>> master) I can't seem to get "import Foundation" or "import Glibc"
>>> working in the REPL. Here's an example:
>>> 
>>> -8<--
>>> $ swift
>>> Welcome to Swift version 3.1-dev (LLVM 7d4a331ed3, Clang d8c33dc710,
>>> Swift 2ea7951d05). Type :help for assistance.
>>> 1> import Glibc
>>> :3:10: note: in file included from :3:
>>> #include "///usr/include/utmp.h"
>>>^
>>> 
>>> ///usr/include/utmp.h:23:10: note: in file included from
>>> ///usr/include/utmp.h:23:
>>> #include 
>>>^
>>> 
>>> error: /usr/include/x86_64-linux-gnu/sys/types.h:146:10: error:
>>> 'stddef.h' file not found
>>> #include 
>>>^
>>> 
>>> error: could not build Objective-C module 'SwiftGlibc'
>>> -8<--
>>> 
>>> 
>>> This works fine if I use 'swiftc' and compile a file:
>>> 
>>> $ cat x.swift
>>> import Glibc
>>> 
>>> print(random())
>>> 
>>> $ swiftc x.swift
>>> $ ./x
>>> ...
>>> -8<--
>>> 
>>> If I explicitly pass include paths to 'swift' it works in the REPL:
>>> 
>>> -8<--
>>> $ swift -I/home/user/swift-install/usr/lib/swift/clang/include/
>>> -I/home/user/swift-install/usr/include/lldb/Symbol/
>>> Welcome to Swift version 3.1-dev (LLVM 7d4a331ed3, Clang d8c33dc710,
>>> Swift 2ea7951d05). Type :help for assistance.
>>> 1> import Glibc
>>> 2> random()
>>> $R0: Int = 1804289383
>>> -8<--
>>> 
>>> Is there some setting or installation setup step I'm missing?
>>> 
>>> -- 
>>> http://bluishcoder.co.nz 
>>> ___
>>> 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 mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Importing Foundation or Glibc in REPL on Ubuntu 16.10 failing

2017-01-30 Thread Michael Gottesman via swift-users
Interesting... it looks like we /do/ have an integration test that imports 
glibc into the repl:

https://github.com/apple/swift-integration-tests/blob/master/repl/test-repl-glibc.py
 


Probably could use one that imports Foundation though.

Michael


> On Jan 30, 2017, at 12:00 PM, Michael Gottesman  wrote:
> 
> Hmm... this sounds like this may be a good integration test. I am not sure 
> what is going on here though. If I have a moment I will take a look a bit 
> later today.
> 
> Michael
> 
>> On Jan 28, 2017, at 1:22 PM, Peter Ronnquist via swift-users 
>>  wrote:
>> 
>> I have the same problem with importing Glibc into the REPL with "Swift
>> 3.1 Development", Ubuntu 16.10, Jan 22, 2017, that was reported on the
>> snapshot from 15 December (see below).
>> 
>> Is this working for anyone?
>> 
>> Best Regards
>> Peter Ronnquist
>> 
>> 
>> 
>> 
>> 
>> On Monday 19 December Chris Double wrote:
>> 
>> 
>> 
>> Using the Ubuntu 16.10 snapshot from 15 December (or a build from
>> master) I can't seem to get "import Foundation" or "import Glibc"
>> working in the REPL. Here's an example:
>> 
>> -8<--
>> $ swift
>> Welcome to Swift version 3.1-dev (LLVM 7d4a331ed3, Clang d8c33dc710,
>> Swift 2ea7951d05). Type :help for assistance.
>> 1> import Glibc
>> :3:10: note: in file included from :3:
>> #include "///usr/include/utmp.h"
>>^
>> 
>> ///usr/include/utmp.h:23:10: note: in file included from
>> ///usr/include/utmp.h:23:
>> #include 
>>^
>> 
>> error: /usr/include/x86_64-linux-gnu/sys/types.h:146:10: error:
>> 'stddef.h' file not found
>> #include 
>>^
>> 
>> error: could not build Objective-C module 'SwiftGlibc'
>> -8<--
>> 
>> 
>> This works fine if I use 'swiftc' and compile a file:
>> 
>> $ cat x.swift
>> import Glibc
>> 
>> print(random())
>> 
>> $ swiftc x.swift
>> $ ./x
>> ...
>> -8<--
>> 
>> If I explicitly pass include paths to 'swift' it works in the REPL:
>> 
>> -8<--
>> $ swift -I/home/user/swift-install/usr/lib/swift/clang/include/
>> -I/home/user/swift-install/usr/include/lldb/Symbol/
>> Welcome to Swift version 3.1-dev (LLVM 7d4a331ed3, Clang d8c33dc710,
>> Swift 2ea7951d05). Type :help for assistance.
>> 1> import Glibc
>> 2> random()
>> $R0: Int = 1804289383
>> -8<--
>> 
>> Is there some setting or installation setup step I'm missing?
>> 
>> -- 
>> http://bluishcoder.co.nz
>> ___
>> 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


Re: [swift-users] TWISt-shout Newsletter 2017-01-30

2017-01-30 Thread Kenny Leung via swift-users
Hi All.

Here is your TWISt-shout Newsletter for the week of 2017-01-23 to 2017-01-29

https://github.com/pepperdog/TWISt-shout/blob/master/2017/TWISt-shout-2017-01-30.md
 


Enjoy!

-Kenny

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


Re: [swift-users] @NSCopying semantic does not appear to copy in Swift initializer

2017-01-30 Thread Torin Kwok via swift-users
Haha yes, you're right. I misunderstanded your idea, sorry. Indeed, in
Obj-C, we have the freedom to decide on whether or not assign a value to
a property by invoking setter or by accessing ivar directly and Apple's
official documentation apparently suggested that we should always access
the instance variables directly from within an initialization
method. That's reasonable, necessary and the best practice as well.

But I suppose what's the really tricky is not "whether we should invoke
setter in initializers" but the confusion made by the inconsistency of
`@NSCopying` attribute's behaviour in Swift.

I have reposted this issue on **swift-evolution** list, please see some
particular replies about that within this thread here:

- 


- 


Thanks!

Quinn The Eskimo! via swift-users writes:

> On 30 Jan 2017, at 10:12, Torin Kwok  wrote:
>
>> In Obj-C, if a property has promised that it conforms to 
>> porotocl and that it would respect copying semantic by being qualified
>> with `@property (copy)`, then we assign a value to `ivar` through the
>> setter by writting down `self.ivar = whatever` in `-init` …
>
> You can do that if you choose to, but the Objective-C convention is to use 
> direct ivar access in `-init` and `-dealloc`.  This is explicitly called out 
> in the “Access Instance Variables Directly from Initializer Methods” section 
> of “Programming with Objective-C”, which says:
>
>> You should always access the instance variables directly from within an 
>> initialization method …
>
> 
>
> For an object with a copyable property `name`, the `-init` method would look 
> like this:
>
> - (instancetype)initWithName:(NSString *)name {
> self = [super init];
> if (self != nil) {
> self->_name = [name copy];
> }
> return self;
> }
>
> Share and Enjoy


-- 
Torin Kwok (郭桐)
OpenPGP/GnuPG: https://keybase.io/kwok
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] @NSCopying semantic does not appear to copy in Swift initializer

2017-01-30 Thread Quinn "The Eskimo!" via swift-users

On 30 Jan 2017, at 10:12, Torin Kwok  wrote:

> In Obj-C, if a property has promised that it conforms to 
> porotocl and that it would respect copying semantic by being qualified
> with `@property (copy)`, then we assign a value to `ivar` through the
> setter by writting down `self.ivar = whatever` in `-init` …

You can do that if you choose to, but the Objective-C convention is to use 
direct ivar access in `-init` and `-dealloc`.  This is explicitly called out in 
the “Access Instance Variables Directly from Initializer Methods” section of 
“Programming with Objective-C”, which says:

> You should always access the instance variables directly from within an 
> initialization method …



For an object with a copyable property `name`, the `-init` method would look 
like this:

- (instancetype)initWithName:(NSString *)name {
self = [super init];
if (self != nil) {
self->_name = [name copy];
}
return self;
}

Share and Enjoy
--
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware


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


Re: [swift-users] @NSCopying semantic does not appear to copy in Swift initializer

2017-01-30 Thread Quinn "The Eskimo!" via swift-users

On 27 Jan 2017, at 18:56, Jordan Rose via swift-users  
wrote:

> @NSCopying currently does not affect initializers.  … it's not 100%, for-sure 
> a bug.

Just by way of context, this current behaviour closely matches Objective-C 
conventions, where `-init` methods directly access ivars and are expected to do 
any necessary copies.

Share and Enjoy
--
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware


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


Re: [swift-users] SwiftPM package naming question

2017-01-30 Thread Ankit Aggarwal via swift-users
Feel free to send a sample package you're having issue with!

On Mon, Jan 30, 2017 at 1:47 PM, David Sweeris via swift-users <
swift-users@swift.org> wrote:

>
> On Jan 29, 2017, at 11:56 PM, Ankit Aggarwal 
> wrote:
>
> The package manager will pick name from manifest if the sources are inside
> Sources directory or in the root directory.
>
> Documentation here:  https://github.com/apple/swif
> t-package-manager/blob/master/Documentation/Reference.md#
> module-format-reference
>
>
> Yeah, I thought so… it seems to be working on one set of packages, but not
> on another. I’ll have to poke at it some more.
>
> ___
> 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