Re: [swift-users] Localization in Swift.

2016-11-01 Thread Zhao Xin via swift-users
I have already give a workable implementation above.

let count = 10
> let says = NSLocalizedString("
> ​blabla
> \(count)
> ​blabla
> ", comment: "
> ​blabla
> ")


​to

let says =
> String.localizedStringWithFormat(NSLocalizedString("​blabla%​@​blabla",
> comment: "​blabla"), ​String(​count​)​


When encounter​ `NSLocalizedString`, Swift looks into its key, if it
​s key​
contains \(foo), just replace it as
`String.localizedStringWithFormat(NSLocalizedString("​blabla%​@​blabla",
comment: "​blabla"), ​String(​foo​)​`. If not, keep it unchanged.

That is enough.

In current situation, Swift still first calculates the value of string
first, then `NSLocalizedString` work. So it just needs to add a little work
to check if there is  any `\(foo)` in the string, instead of calculating
the value of string.

Zhaoxin

On Wed, Nov 2, 2016 at 2:09 PM, Jens Alfke  wrote:

>
> > On Nov 1, 2016, at 10:56 PM, Zhao Xin  wrote:
> >
> > I am not talking to eliminate "%" style function. I am talking to add
> more compatibility to `NSLocalizedString` with `\(foo)` style.
>
> I don’t think the ExpressibleByStringInterpolation protocol provides
> enough information to make this work. It hands the implementation a list of
> values to concatenate, some of which are strings, but as far as I can tell
> there’s no way to tell which of those strings are the pieces of the string
> literal and which of them are the results of expressions. So
> NSLocalizedString would not be able to reassemble the string template that
> you gave it, to look up in the localization table.
>
> If I’m wrong about this, show me a workable implementation of it. :)
>
> Also, ExpressibleByStringInterpolation is marked as being deprecated and
> will be “replaced or redesigned in Swift 4.0.” Maybe to solve this
> limitation?
>
> —Jens
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift and Xcode along with Playgrounds is full of bugs

2016-11-01 Thread Shyamal Chandra via swift-users
Hi Jens,

1. I think you have me confused; I am not yelling.  I didn't flame Tim Cook
or Chris Latter.
2. Github would be a great place to use for the extensible documentation.
3. Volunteers are great because they might get jobs from Apple or become
great evangelists for knowing industry-quality code
4. They could sell Venmo or PayPal support and build an ecosystem of
support at lower prices that are super fast with nanopayments (e.g.
Muhammad Yunus).
5. Everyone should be on first name basis with Tim because he is going to
help us in some way with his hands-on and administrative decisions both in
policy and implementation.  Wait, I sent a letter once to Satya Nadella and
he sent me a better grade headset.  Customer engagement should be personal,
not hierarchical.
6. From my limited MSM perspective and Walter Isaacson's book on Steve
Jobs, I cannot comment on the "nail my head to the floor".  This type of
anecdotal way of circumventing the issue might be best addressed with a
phone number.  I included my phone number. :-)
7. My CPU is not being used 100%; even then, why is the app still loading
and not doing on-the-fly compilation (I am unsure what it is doing without
debug mode.)?  Do you use design patterns or concurrency patterns to fully
utilize the number of cores with an adequate number of processes and
threads in the background and foreground.  I wish I had a Mac Pro (I have a
3-year-old iMac) and even if I upgrade, would the performance scale and
speed up?


Thanks!

Best,

Shyamal Chandra
shyam...@gmail.com
Linkedin: http://www.linkedin.com/in/shyamalc
Phone: 620-719-9064

On Wed, Nov 2, 2016 at 1:03 AM, Jens Alfke  wrote:

>
> On Nov 1, 2016, at 9:50 PM, Shyamal Chandra via swift-users <
> swift-users@swift.org> wrote:
>
> Why don't you make the Playgrounds open source so I can investigate?
>
>
> I’ve been hearing people tell Apple “why don’t you make ___ open source”
> for as long as the term ‘open source’ has existed. Sometimes it happens,
> but the decision doesn’t seem to be based on factors like ‘people on the
> Internet are yelling at us to open-source this’, or ‘this feature sucks,
> let’s dump the source code on Github and let volunteers fix it for us for
> free!’
>
> I’m being sarcastic here, but if you’d ever run an open source project —
> or worse, open-sourced an existing code base — you’d have some idea of the
> complexity of what you’re asking. Open source is a commitment, and it can
> be a ton of work just getting the code ready, especially when it has
> dependencies on private APIs from other components that shouldn’t be
> exposed. Even comments and identifiers need to be scrubbed of references to
> internal/secret/embarrassing information, like “// we’re commenting out
> this feature until the 2017 Mac Pro ships in March”, or “// Workaround to
> make Photoshop compile, no thanks to those morons at Adobe”. (Yes, I went
> through stuff like this in one project in the ‘90s.)
>
> As for Playgrounds, I’m not aware of Apple open-sourcing GUI-level
> application code. Ever. (Someone correct me if I’ve forgotten something.)
>
> You should tell this to Tim Cook as soon as possible.
>
>
> Because everyone at Apple is on a first-name basis with Tim Cook and feels
> free to drop into his office and tell him what to do. 🙄 Back when I worked
> at Apple I used to drop in on Steve and tell him the metal UI appearance
> sucked. He’d chuckle in his kindly way, and then nail my head to the floor.
>
> —Jens
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Localization in Swift.

2016-11-01 Thread Jens Alfke via swift-users

> On Nov 1, 2016, at 10:56 PM, Zhao Xin  wrote:
> 
> I am not talking to eliminate "%" style function. I am talking to add more 
> compatibility to `NSLocalizedString` with `\(foo)` style.

I don’t think the ExpressibleByStringInterpolation protocol provides enough 
information to make this work. It hands the implementation a list of values to 
concatenate, some of which are strings, but as far as I can tell there’s no way 
to tell which of those strings are the pieces of the string literal and which 
of them are the results of expressions. So NSLocalizedString would not be able 
to reassemble the string template that you gave it, to look up in the 
localization table.

If I’m wrong about this, show me a workable implementation of it. :)

Also, ExpressibleByStringInterpolation is marked as being deprecated and will 
be “replaced or redesigned in Swift 4.0.” Maybe to solve this limitation?

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


Re: [swift-users] Swift and Xcode along with Playgrounds is full of bugs

2016-11-01 Thread Jens Alfke via swift-users

> On Nov 1, 2016, at 9:50 PM, Shyamal Chandra via swift-users 
>  wrote:
> 
> Why don't you make the Playgrounds open source so I can investigate? 

I’ve been hearing people tell Apple “why don’t you make ___ open source” for as 
long as the term ‘open source’ has existed. Sometimes it happens, but the 
decision doesn’t seem to be based on factors like ‘people on the Internet are 
yelling at us to open-source this’, or ‘this feature sucks, let’s dump the 
source code on Github and let volunteers fix it for us for free!’

I’m being sarcastic here, but if you’d ever run an open source project — or 
worse, open-sourced an existing code base — you’d have some idea of the 
complexity of what you’re asking. Open source is a commitment, and it can be a 
ton of work just getting the code ready, especially when it has dependencies on 
private APIs from other components that shouldn’t be exposed. Even comments and 
identifiers need to be scrubbed of references to internal/secret/embarrassing 
information, like “// we’re commenting out this feature until the 2017 Mac Pro 
ships in March”, or “// Workaround to make Photoshop compile, no thanks to 
those morons at Adobe”. (Yes, I went through stuff like this in one project in 
the ‘90s.)

As for Playgrounds, I’m not aware of Apple open-sourcing GUI-level application 
code. Ever. (Someone correct me if I’ve forgotten something.)

> You should tell this to Tim Cook as soon as possible.

Because everyone at Apple is on a first-name basis with Tim Cook and feels free 
to drop into his office and tell him what to do. 🙄 Back when I worked at Apple 
I used to drop in on Steve and tell him the metal UI appearance sucked. He’d 
chuckle in his kindly way, and then nail my head to the floor.

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


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 at 1:49 PM, Jens Alfke  wrote:

>
> > On Nov 1, 2016, at 10:40 PM, Zhao Xin  wrote:
> >
> > For example, if I want show the user that I have to ask him to give me
> permission of a folder, the `url.path` has no need to translate.
>
> We’re getting off-topic, but paths do need to be translated, at least on
> Mac systems. The names of many standard folders like “Applications” and
> “Documents” are hardwired to English in the filesystem but are localized in
> the UI. Some application names get localized too (there’s a table in the
> app’s Info.plist that can substitute localized names.)
>
> Anyway, string interpolation is convenient, but I wouldn’t say it should
> be the only way to format strings in Swift; it’s a lot less flexible than
> the C-style “%” substitutions. For comparison, even though C++’s iostreams
> use “<<“ to format strings by concatenation, I still end up using “%” based
> formatting a lot, depending on the use case.
>
> —Jens
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Localization in Swift.

2016-11-01 Thread Jens Alfke via swift-users

> On Nov 1, 2016, at 10:40 PM, Zhao Xin  wrote:
> 
> For example, if I want show the user that I have to ask him to give me 
> permission of a folder, the `url.path` has no need to translate.

We’re getting off-topic, but paths do need to be translated, at least on Mac 
systems. The names of many standard folders like “Applications” and “Documents” 
are hardwired to English in the filesystem but are localized in the UI. Some 
application names get localized too (there’s a table in the app’s Info.plist 
that can substitute localized names.)

Anyway, string interpolation is convenient, but I wouldn’t say it should be the 
only way to format strings in Swift; it’s a lot less flexible than the C-style 
“%” substitutions. For comparison, even though C++’s iostreams use “<<“ to 
format strings by concatenation, I still end up using “%” based formatting a 
lot, depending on the use case.

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


Re: [swift-users] Localization in Swift.

2016-11-01 Thread Zhao Xin via swift-users
I has known that, and it is the developer's choice,  which means, the
developer has already known that. There are many circumstances that there
are no needs to translate at all. For example, if I want show the user that
I have to ask him to give me permission of a folder, the `url.path` has no
need to translate.

And of course,
` String.localizedStringWithFormat(NSLocalizedString("​blabla%​@​blabla",
comment: "​blabla"), ​` has already allows to do that. I just think it
should be in a more Swift way by using `\(foo)`.

Zhaoxin

On Wed, Nov 2, 2016 at 11:45 AM, Jens Alfke  wrote:

>
> On Nov 1, 2016, at 7:52 PM, Zhao Xin  wrote:
>
> The second should be
>
> let says = String.localizedStringWithFormat(NSLocalizedString("
>> ​blabla
>> %
>> ​@
>> ​blabla
>> ", comment: "
>> ​blabla
>> "),
>> ​String(​
>> count
>> ​)​
>> )
>
>
> That’s not quite right, because the conversion of `count` to a string
> won’t be localized. Some languages use non-ASCII digits, use characters
> other than “.” for decimal points, etc. Depending on the exact type of
> `count`, it would need to be something like:
>
> String.localizedStringWithFormat(NSLocalizedString("​blabla%​d​blabla",
> comment: "​blabla"), ​count​)​
>
> Hardcoding this specific kind of transformation into the parser seems like
> a bad idea, since NSLocalizedString isn’t part of the language. Why don’t
> you just use localizedStringWithFormat instead of string interpolation in
> your code?
>
> —Jens
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Fwd: Swift and Xcode along with Playgrounds is full of bugs

2016-11-01 Thread Shyamal Chandra via swift-users
Hi Tim,

Hope you are doing well!

The quality of response time and stability of Xcode Playgrounds is
questionable.  Also, the support and forum response time are not adequate.
Could you please open-source Xcode Playgrounds so I can look at the source
code to fix the problems or provide better documentation for the
XCPlayground library which has sparse documentation on the web and on the
Apple website?

Thanks!

Best,

Shyamal Chandra
shyam...@gmail.com
Linkedin: http://www.linkedin.com/in/shyamalc
Phone: 620-719-9064

-- Forwarded message --
From: Shyamal Chandra 
Date: Tue, Nov 1, 2016 at 11:50 PM
Subject: Re: [swift-users] Swift and Xcode along with Playgrounds is full
of bugs
To: Chris Lattner 
Cc: Shyamal Chandra via swift-users 


Hi Chris,

First of all, there is tremendous instability with Xcode Playgrounds.  I
paste the same simple code into Xcode Playgrounds; sometimes, it works and
sometimes, it doesn't work.  Why don't you make the Playgrounds open source
so I can investigate?  You should tell this to Tim Cook as soon as
possible.  I wanted to add Swift to the list of languages in Juypter for
workbook usage.  If a project is closed-source, I cannot do anything
without looking at documented code.  The documentation for Xcode
Playgrounds is not there.  For the XCPlayground library, there is just an
API call reference that is sparsely documented.   I can wait for infinity
for a response on the forums but Apple should provide better support rather
than charging money for each technical support call.  This is disappointing
since Apple was founded to make computing easy, not hard on purpose, making
code writing a black art.

Thanks!

Best,

Shyamal Chandra
shyam...@gmail.com
Linkedin: http://www.linkedin.com/in/shyamalc
Phone: 620-719-9064

On Tue, Sep 13, 2016 at 10:56 PM, Chris Lattner  wrote:

> On Sep 13, 2016, at 5:34 PM, Shyamal Chandra  wrote:
>
> Hi Chris,
>
> Here is a forum question that I posted a while back.  The latest post says
> to file a bug under the bug report.
>
>
> Here's the post:
>
> https://forums.developer.apple.com/thread/61953 (Playgrounds error)
>
>
> Thanks for the link.  Contrary to your claims, it appears that you
> promptly got a response from an Apple employee, and it appears that you
> didn’t follow his instructions to file a radar in bugreporter.apple.com.
>
> Now that Xcode 8 has shipped to the Mac App Store today, I’d suggest you
> download that and try it.  There are a number of bugs that are fixed
> between beta 6 and the final release, and that may include this one.
>
> I was doing something "simple" in Playgrounds and my version of
> Playgrounds doesn't function properly because it is emitting an error when
> I write bug-free code.  Why is Playgrounds so flaky?  Sometimes, it shows
> the output on the right side; sometime, it doesn’t.
>
>
> Two simple and obvious answers come to mind: you are running
> advertised-as-beta software, and even shipping software does have bugs.
>
> I have had mixed success with the bug reporter tool from Apple; most of
> the time, they ask for the system diagnostics and then, tell you to update
> your version.  Sometimes, they just close the issue and nothing happens.
>
>
> I understand that you claim to have had problems with Radar/
> bugreporter.apple.com, but again I can see no evidence of you ever filing
> a bug in it (and you haven’t provided me any radar numbers to cross
> reference), so there isn’t much I can do to help you.  Needless to say, we
> do actually need the system diagnostics in order to reproduce issues like
> this, as you found on the forum, your issue doesn’t reproduce trivially for
> other folks.
>
>
> Finally, as others have pointed out, your approach on this thread hasn’t
> been particularly constructive.  Despite your apparent expectation, Apple
> has not signed up to fix any and every bug reported against Swift.  That
> said, we all want to build a strong community, and if you are interested in
> working in a helpful and productive way we would love for you to be part of
> that community.  On the other hand, if you find that Swift on Linux isn’t
> ready for you today and that you don’t want to invest effort in it, then
> perhaps it is best for you to come back at some point later in the future.
>
> Thanks,
>
> -Chris
>
>
>
> Thanks!
>
> Best,
>
> Shyamal Chandra
> shyam...@gmail.com
> Linkedin: http://www.linkedin.com/in/shyamalc
> Phone: 620-719-9064
>
> On Tue, Sep 13, 2016 at 7:02 PM, Chris Lattner  wrote:
>
>> On Sep 12, 2016, at 3:03 PM, Shyamal Chandra via swift-users <
>> swift-users@swift.org> wrote:
>> > Hope you are doing well!
>> >
>> > Swift is very volatile language that keeps on changing with every new
>> version of Xcode.  When you are trying to run old code with different
>> syntax, you run into problems because the code is no longer compatible.
>> Instead of moving onto Swift 3, 4, and 5 (with different syntax), why don't
>> you standardize the library and language operation

Re: [swift-users] Swift and Xcode along with Playgrounds is full of bugs

2016-11-01 Thread Shyamal Chandra via swift-users
Hi Chris,

First of all, there is tremendous instability with Xcode Playgrounds.  I
paste the same simple code into Xcode Playgrounds; sometimes, it works and
sometimes, it doesn't work.  Why don't you make the Playgrounds open source
so I can investigate?  You should tell this to Tim Cook as soon as
possible.  I wanted to add Swift to the list of languages in Juypter for
workbook usage.  If a project is closed-source, I cannot do anything
without looking at documented code.  The documentation for Xcode
Playgrounds is not there.  For the XCPlayground library, there is just an
API call reference that is sparsely documented.   I can wait for infinity
for a response on the forums but Apple should provide better support rather
than charging money for each technical support call.  This is disappointing
since Apple was founded to make computing easy, not hard on purpose, making
code writing a black art.

Thanks!

Best,

Shyamal Chandra
shyam...@gmail.com
Linkedin: http://www.linkedin.com/in/shyamalc
Phone: 620-719-9064

On Tue, Sep 13, 2016 at 10:56 PM, Chris Lattner  wrote:

> On Sep 13, 2016, at 5:34 PM, Shyamal Chandra  wrote:
>
> Hi Chris,
>
> Here is a forum question that I posted a while back.  The latest post says
> to file a bug under the bug report.
>
>
> Here's the post:
>
> https://forums.developer.apple.com/thread/61953 (Playgrounds error)
>
>
> Thanks for the link.  Contrary to your claims, it appears that you
> promptly got a response from an Apple employee, and it appears that you
> didn’t follow his instructions to file a radar in bugreporter.apple.com.
>
> Now that Xcode 8 has shipped to the Mac App Store today, I’d suggest you
> download that and try it.  There are a number of bugs that are fixed
> between beta 6 and the final release, and that may include this one.
>
> I was doing something "simple" in Playgrounds and my version of
> Playgrounds doesn't function properly because it is emitting an error when
> I write bug-free code.  Why is Playgrounds so flaky?  Sometimes, it shows
> the output on the right side; sometime, it doesn’t.
>
>
> Two simple and obvious answers come to mind: you are running
> advertised-as-beta software, and even shipping software does have bugs.
>
> I have had mixed success with the bug reporter tool from Apple; most of
> the time, they ask for the system diagnostics and then, tell you to update
> your version.  Sometimes, they just close the issue and nothing happens.
>
>
> I understand that you claim to have had problems with Radar/
> bugreporter.apple.com, but again I can see no evidence of you ever filing
> a bug in it (and you haven’t provided me any radar numbers to cross
> reference), so there isn’t much I can do to help you.  Needless to say, we
> do actually need the system diagnostics in order to reproduce issues like
> this, as you found on the forum, your issue doesn’t reproduce trivially for
> other folks.
>
>
> Finally, as others have pointed out, your approach on this thread hasn’t
> been particularly constructive.  Despite your apparent expectation, Apple
> has not signed up to fix any and every bug reported against Swift.  That
> said, we all want to build a strong community, and if you are interested in
> working in a helpful and productive way we would love for you to be part of
> that community.  On the other hand, if you find that Swift on Linux isn’t
> ready for you today and that you don’t want to invest effort in it, then
> perhaps it is best for you to come back at some point later in the future.
>
> Thanks,
>
> -Chris
>
>
>
> Thanks!
>
> Best,
>
> Shyamal Chandra
> shyam...@gmail.com
> Linkedin: http://www.linkedin.com/in/shyamalc
> Phone: 620-719-9064
>
> On Tue, Sep 13, 2016 at 7:02 PM, Chris Lattner  wrote:
>
>> On Sep 12, 2016, at 3:03 PM, Shyamal Chandra via swift-users <
>> swift-users@swift.org> wrote:
>> > Hope you are doing well!
>> >
>> > Swift is very volatile language that keeps on changing with every new
>> version of Xcode.  When you are trying to run old code with different
>> syntax, you run into problems because the code is no longer compatible.
>> Instead of moving onto Swift 3, 4, and 5 (with different syntax), why don't
>> you standardize the library and language operations and functions for the
>> different package and frameworks included with Xcode
>>
>> The subject line of this message seems like it is intended to be
>> provocative, not helpful.
>>
>> Despite that, you’ll be happy to know that the goal of Swift 4 is to be
>> source compatible with Swift 3, so the concerns that you are complaining
>> about are historic, not future problems.
>>
>> > because I have already submitted multiple bugs to the bug report that
>> are with the official release of Xcode and I am very disappointed with the
>> software quality.
>>
>> I don’t see any radars filed by you in the system, but perhaps they are
>> just under a different name.  In any case, thank you for filing bugs, we do
>> read and care about them!  Please send me the ra

Re: [swift-users] Localization in Swift.

2016-11-01 Thread Jens Alfke via swift-users

> On Nov 1, 2016, at 7:52 PM, Zhao Xin  wrote:
> 
> The second should be
> 
> let says = 
> String.localizedStringWithFormat(NSLocalizedString("​blabla%​@​blabla", 
> comment: "​blabla"), ​String(​count​)​)

That’s not quite right, because the conversion of `count` to a string won’t be 
localized. Some languages use non-ASCII digits, use characters other than “.” 
for decimal points, etc. Depending on the exact type of `count`, it would need 
to be something like:

String.localizedStringWithFormat(NSLocalizedString("​blabla%​d​blabla", 
comment: "​blabla"), ​count​)​

Hardcoding this specific kind of transformation into the parser seems like a 
bad idea, since NSLocalizedString isn’t part of the language. Why don’t you 
just use localizedStringWithFormat instead of string interpolation in your code?

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


Re: [swift-users] Localization in Swift.

2016-11-01 Thread Zhao Xin via swift-users
The second should be

let says = String.localizedStringWithFormat(NSLocalizedString("
> ​blabla
> %
> ​@
> ​blabla
> ", comment: "
> ​blabla
> "),
> ​String(​
> count
> ​)​
> )


​Zhaoxin​

On Wed, Nov 2, 2016 at 10:50 AM, Zhao Xin  wrote:

> I think in Swift.
>
> let count = 10
>> let says = NSLocalizedString("
>> ​blabla
>> \(count)
>> ​blabla
>> ", comment: "
>> ​blabla
>> ")
>
>
> ​can be roughly interpreted as
>
> let says = String.localizedStringWithFormat(NSLocalizedString("
>> ​blabla
>> %
>> ​@
>> ​blabla
>> ", comment: "
>> ​blabla
>> "), count)
>
>
> ​So if Swift does not want to do much effort on this ​, it could just find
> every 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  wrote:
>
>>
>> > On Nov 1, 2016, at 1:53 AM, Zhao Xin via swift-users <
>> swift-users@swift.org> wrote:
>> >
>> > I began to realize that` \(count)` was not dealed well in localization.
>> The compiler calculated the full string then looking for the translation,
>> instead of looking for the translation first.
>>
>> NSLocalizedString was designed (in the 1990s) to be used with methods
>> like String(format:…) that take printf-style “%”-substituted format strings.
>> Swift’s string interpolation is obviously a different mechanism entirely.
>>
>> I suspect that Swift interpolation won’t work well for localized strings
>> because the string and the code are so tightly connected. Localization very
>> often needs to change the order of parameters, for instance. It’s also
>> unclear where things like number formatting happen in Swift interpolation;
>> when localizing a string, the conversion needs to be done using the same
>> locale as the string lookup, which might not happen if the string-to-number
>> conversion is separate and uses the default locale.
>>
>> —Jens
>
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Localization in Swift.

2016-11-01 Thread Zhao Xin via swift-users
I think in Swift.

let count = 10
> let says = NSLocalizedString("
> ​blabla
> \(count)
> ​blabla
> ", comment: "
> ​blabla
> ")


​can be roughly interpreted as

let says = String.localizedStringWithFormat(NSLocalizedString("
> ​blabla
> %
> ​@
> ​blabla
> ", comment: "
> ​blabla
> "), count)


​So if Swift does not want to do much effort on this ​, it could just find
every 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  wrote:

>
> > On Nov 1, 2016, at 1:53 AM, Zhao Xin via swift-users <
> swift-users@swift.org> wrote:
> >
> > I began to realize that` \(count)` was not dealed well in localization.
> The compiler calculated the full string then looking for the translation,
> instead of looking for the translation first.
>
> NSLocalizedString was designed (in the 1990s) to be used with methods like
> String(format:…) that take printf-style “%”-substituted format strings.
> Swift’s string interpolation is obviously a different mechanism entirely.
>
> I suspect that Swift interpolation won’t work well for localized strings
> because the string and the code are so tightly connected. Localization very
> often needs to change the order of parameters, for instance. It’s also
> unclear where things like number formatting happen in Swift interpolation;
> when localizing a string, the conversion needs to be done using the same
> locale as the string lookup, which might not happen if the string-to-number
> conversion is separate and uses the default locale.
>
> —Jens
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Type checker not accepting subclass(protocol conformance) as a valid type inside a closure in a protocol with constraint where Self: MyClass

2016-11-01 Thread Henrique Valcanaia via swift-users
Hey everyone.

I’m having some trouble with the following code, more precisely I’m getting the 
error "Cannot convert value of type '([Self]?, Error?) -> Void?' to expected 
argument type ‘([SomeModel]?, Error?) -> Void?’” when trying to call 
“find2(withBlock: ([SomeModel]?, Error?) -> Void?)” inside my extension.

Here’s a snippet:

protocol SomeModel { }

func find2(withBlock block: ([SomeModel]?, Error?) -> Void?) {
print(#function)
}

protocol PersistentModel {
typealias FindBlock = (_ objs: [Self]?, _ error: Error?) -> Void?
func find(withBlock block: FindBlock)
}

extension PersistentModel where Self: SomeModel {
func find(withBlock block: FindBlock) {
   find2(withBlock: block)
}
}

Considering I’m constraining my protocol extension to SomeModel, why do I get 
the error when trying to call “find(withBlock: ([SomeModel]?, Error?) -> 
Void?)”? It’s seems to me the type checker is not comparing the parameters' 
type inside the block and its inheritances/protocol conformances.

Just for testing purposes I created a simple class implementing the protocol 
and a function with the parameter of the same type, we can see the problem does 
not occur, being strictly linked to closures.

class MyClass: SomeModel { }

func test(a: SomeModel) { }
test(a: MyClass())

I’m not sure if I’m doing something wrong or if it is just a compiler/language 
limitation, any thoughts?

Thanks

- Henrique

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


Re: [swift-users] Custom little/big endian data structure.

2016-11-01 Thread Adrian Zubarev via swift-users
Hi Chris,

thank you for your answer. I can’t wait for property behaviors, it’s going to 
be such a powerful feature. :)

-- 
Adrian Zubarev
Sent with Airmail

Am 1. November 2016 um 18:34:55, Chris Lattner (clatt...@apple.com) schrieb:


On Oct 30, 2016, at 12:50 PM, Adrian Zubarev via swift-users 
 wrote:

Hi there,

is there actually a way to build a custom data structure that will 
automatically be converted to little/big endian on a little/big endian system, 
just like (U)Int16/32/64 do?

I could build as a workaround a mechanism that will do that for me, but I’m 
curious if this is possible with some workaround. 

Hi Adrian,

This isn’t something that Swift provides a magic answer to today, but it seems 
possible that the “property behaviors” proposal (which is currently shelved, 
but will hopefully come back in the future) could be used to address this.

-Chris

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


Re: [swift-users] What is "binding" memory?

2016-11-01 Thread Andrew Trick via swift-users

> On Nov 1, 2016, at 11:55 AM, Manfred Schubert via swift-users 
>  wrote:
> 
> The "UnsafeRawPointer Migration" guide talks about "binding memory to a type“ 
> as if that was a well known term. I have never heard of it yet though, and 
> googling it returns no relevant results. I do not understand what binding 
> memory is supposed to do.
> 
> The migration guide says "Binding uninitialized memory to a type prepares the 
> memory to store values of that type“, but clearly raw memory does not need to 
> be prepared (and cannot be) to hold any arbitrary type and value.
> 
> So what is this for, what does it actually do, and to whom is it done (the 
> raw pointer, or the typed pointer which is returned, or the raw memory)?
> 
> 
> Manfred

Hi Manfred,

At the top of the migration guide is a link to the memory model explanation:
https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#memory-model-explanation

"A memory location's bound type is an abstract, dynamic property of the memory 
used to formalize type safety.”

I’m not sure I like the “prepares the memory” language myself. Binding memory 
communicates to the compiler that the memory locations are safe for typed 
access. Nothing happens at runtime--until someone writes a type safety 
sanitizer. It affects the abstract state of the memory location, independent of 
the pointer variable used to access that memory. Binding memory returns a typed 
pointer for convenience and clarity, but there’s nothing special about that 
particular pointer value.

Initialized memory is always bound to some type. A rawpointer can be used to 
access that memory without knowing its bound type.

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


Re: [swift-users] What is "binding" memory?

2016-11-01 Thread Michael Ilseman via swift-users

> On Nov 1, 2016, at 11:55 AM, Manfred Schubert via swift-users 
>  wrote:
> 
> The "UnsafeRawPointer Migration" guide talks about "binding memory to a type“ 
> as if that was a well known term. I have never heard of it yet though, and 
> googling it returns no relevant results. I do not understand what binding 
> memory is supposed to do.
> 
> The migration guide says "Binding uninitialized memory to a type prepares the 
> memory to store values of that type“, but clearly raw memory does not need to 
> be prepared (and cannot be) to hold any arbitrary type and value.
> 
> So what is this for, what does it actually do, and to whom is it done (the 
> raw pointer, or the typed pointer which is returned, or the raw memory)?
> 

This is more so a semantic distinction rather than some kind of physical 
operation. The memory is not altered, but all reads and writes to that memory 
location have to be through the “bound type”. If it’s “bound” to some type T, 
you must only read and write through values of type T, and not some unrelated 
type. This is in order to honor Swift's memory model while still exposing 
access to raw memory (see [1]), and to do so one must be careful about how they 
treat that memory so as to not violate “strict aliasing” (see [2]). This is 
similar to the notion of strict aliasing in C (see [3]). 

[1] 
https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#memory-model-explanation
 

[2] 
https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#strict-aliasing
[3] http://blog.regehr.org/archives/1307


> 
> Manfred
> ___
> 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] What is "binding" memory?

2016-11-01 Thread Rien via swift-users
The way I understand it, it prepares a memory structure that refers to the ‘raw 
memory’ such that it can be used to access the referenced memory according to 
the type ‘bound’ to.
 
Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http://github.com/Swiftrien
Project: http://swiftfire.nl




> On 01 Nov 2016, at 19:55, Manfred Schubert via swift-users 
>  wrote:
> 
> The "UnsafeRawPointer Migration" guide talks about "binding memory to a type“ 
> as if that was a well known term. I have never heard of it yet though, and 
> googling it returns no relevant results. I do not understand what binding 
> memory is supposed to do.
> 
> The migration guide says "Binding uninitialized memory to a type prepares the 
> memory to store values of that type“, but clearly raw memory does not need to 
> be prepared (and cannot be) to hold any arbitrary type and value.
> 
> So what is this for, what does it actually do, and to whom is it done (the 
> raw pointer, or the typed pointer which is returned, or the raw memory)?
> 
> 
> Manfred
> ___
> 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] What is "binding" memory?

2016-11-01 Thread Manfred Schubert via swift-users
The "UnsafeRawPointer Migration" guide talks about "binding memory to a type“ 
as if that was a well known term. I have never heard of it yet though, and 
googling it returns no relevant results. I do not understand what binding 
memory is supposed to do.

The migration guide says "Binding uninitialized memory to a type prepares the 
memory to store values of that type“, but clearly raw memory does not need to 
be prepared (and cannot be) to hold any arbitrary type and value.

So what is this for, what does it actually do, and to whom is it done (the raw 
pointer, or the typed pointer which is returned, or the raw memory)?


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


[swift-users] please unsubscribe

2016-11-01 Thread Cavit Artanlar via swift-users

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


Re: [swift-users] Custom little/big endian data structure.

2016-11-01 Thread Chris Lattner via swift-users

> On Oct 30, 2016, at 12:50 PM, Adrian Zubarev via swift-users 
>  wrote:
> 
> Hi there,
> 
> is there actually a way to build a custom data structure that will 
> automatically be converted to little/big endian on a little/big endian 
> system, just like (U)Int16/32/64 do?
> 
> I could build as a workaround a mechanism that will do that for me, but I’m 
> curious if this is possible with some workaround. 

Hi Adrian,

This isn’t something that Swift provides a magic answer to today, but it seems 
possible that the “property behaviors” proposal (which is currently shelved, 
but will hopefully come back in the future) could be used to address this.

-Chris

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


Re: [swift-users] Localization in Swift.

2016-11-01 Thread Jens Alfke via swift-users

> On Nov 1, 2016, at 1:53 AM, Zhao Xin via swift-users  
> wrote:
> 
> I began to realize that` \(count)` was not dealed well in localization. The 
> compiler calculated the full string then looking for the translation, instead 
> of looking for the translation first.

NSLocalizedString was designed (in the 1990s) to be used with methods like 
String(format:…) that take printf-style “%”-substituted format strings.
Swift’s string interpolation is obviously a different mechanism entirely.

I suspect that Swift interpolation won’t work well for localized strings 
because the string and the code are so tightly connected. Localization very 
often needs to change the order of parameters, for instance. It’s also unclear 
where things like number formatting happen in Swift interpolation; when 
localizing a string, the conversion needs to be done using the same locale as 
the string lookup, which might not happen if the string-to-number conversion is 
separate and uses the default locale.

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


Re: [swift-users] Element vs. Iterator.Element

2016-11-01 Thread Toni Suter via swift-users
Ok, I have filed a bug: https://bugs.swift.org/browse/SR-3102 


Best regards,
Toni

> Am 31.10.2016 um 19:32 schrieb Dave Abrahams via swift-users 
> :
> 
> 
> on Mon Oct 31 2016, Toni Suter  > wrote:
> 
>> Hi,
>> 
>> This extension on Array works as expected:
>> 
>> extension Array where Element: CustomStringConvertible {
>>func f(_ x: Element) -> String {
>>return x.description
>>}
>> }
>> 
>> But when I use Iterator.Element instead, I get an error message (error: 
>> value of type 'Element' has
>> no member 'description'):
>> 
>> extension Array where Iterator.Element: CustomStringConvertible {
>>func f(_ x: Iterator.Element) -> String {
>>return x.description
>>}
>> }
>> 
>> I assume this is a type checker bug, but before I report it, I wanted to 
>> make sure that that’s
>> really the case. Or is there a difference between Element and
>> Iterator.Element?
> 
> There shouldn't be.  It's a bug, IMO.
> 
> -- 
> -Dave
> 
> ___
> 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] Localization in Swift.

2016-11-01 Thread Brent Royal-Gordon via swift-users
> I managed to replace my code with 
> 
> let newSays = String.localizedStringWithFormat(NSLocalizedString("It runs %d 
> times", comment: "new run times"), count)
> 
> However, I still thing it would be better if we could use \(foo) directly, as 
> it is more Swift style. Any idea why this can't happen?

I have some code that does that (Swift 2 version: 
), but it relies on the 
ExpressibleByStringInterpolation protocol, which is currently deprecated 
because it's due for a redesign.

Ultimately, localization is a Foundation-level concern. I'd love to see a 
future Foundation do something clever with NSLocalizedString, but it seems like 
their hands have been full with higher-priority stuff like the value-type 
equivalents.

-- 
Brent Royal-Gordon
Architechies

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


[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 this error:

[strings] ERROR, It runs 10 times not found in table Localizable of bundle
> CFBundle 0x100c01c40 ... (executable, loaded)
> IT RUNS 10 TIMES


I began to realize that` \(count)` was not dealed well in localization. The
compiler calculated the full string then looking for the translation,
instead of looking for the translation first.

I managed to replace my code with

let newSays = String.localizedStringWithFormat(NSLocalizedString("It runs
> %d times", comment: "new run times"), count)


However, I still thing it would be better if we could use \(foo) directly,
as it is more Swift style. Any idea why this can't happen?

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