How can I make NSString.stringEncodingForData fail?

2016-05-29 Thread Daryle Walker
I'm about to test code that uses this method. My encodings are: ASCII, UTF-8, 
ISO Latin-1, then MacRoman. I think this covers all potential octet values. My 
"guard" blocks (I'm using Swift.) are for a 0 return and if the optional 
returned NSString can't be converted to a String.

Can I cause some fail cases, or is that so unlikely that I should assert on 
non-zero return and use "!" on the optional?

Sent from my iPhone
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Simplest way to generate audio tones?

2016-05-29 Thread Graham Cox
Hi Jonathan,

This turned out to be a great tip - thanks. I was able to port that iOS code 
straight to Mac without any problems and it pretty much worked first time. The 
audio session stuff turned out to be irrelevant to Mac, I just created the AU 
and away it went…

—Graham






> On 29 May 2016, at 3:36 PM, Jonathan Hull  wrote:
> 
> This is way out of my area of expertise, but it appears you want AudioUnits:
> http://www.cocoawithlove.com/2010/10/ios-tone-generator-introduction-to.html
> 
> Thanks,
> Jon


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Simplest way to generate audio tones?

2016-05-29 Thread Jens Alfke

> On May 28, 2016, at 8:24 PM, Graham Cox  wrote:
> 
> I’m looking for general pointers to the simplest/quickest way to generate an 
> audio tone (sine wave) of a given frequency and duration. Most of the audio 
> APIs seem concerned with playing samples rather than generating tones, so 
> it’s not immediately obvious where to look.

It’s easy to generate a sample buffer of a sine wave. Allocate an array of 
uint16_t, and fill in each sample by scaling such that -1 ⟶ 0 and 1 ⟶ 255. Then 
tell whatever API you’re using that it’s a 1-channel 16-bit PCM buffer. Choose 
whatever sample rate you want to make it come out the right frequency; it’ll do 
the interpolation for you.

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: When can String.enumerateSubstringsInRange ever pass in NIL?

2016-05-29 Thread Daryle Walker
Since I am using the substring and not including “.SubstringNotRequired”, I can 
just remove the “guard” block, tack on a “!” to substring’s identifier, and be 
done with it, right?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

> On May 29, 2016, at 12:08 AM, Ken Thomases  wrote:
> 
> On May 28, 2016, at 8:27 PM, Daryle Walker  wrote:
>> 
>> The last argument to the method is a closure with four parameters. The first 
>> argument is an optional String. I can't think of a circumstance where it'll 
>> be NIL. (I need to know for testing.) Especially since it can be recreated 
>> in terms of the callback's second argument, which isn't optional. (So the 
>> string can be empty at worst.). Am I missing something, or is this a bug 
>> (and should be non-optional)?
> 
> One can pass NSStringEnumerationOptions.SubstringNotRequired in the options 
> to tell the framework to not bother creating that substring, which can be 
> expensive, if you don't need it.  In that case, it will pass nil to your 
> block.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: When can String.enumerateSubstringsInRange ever pass in NIL?

2016-05-29 Thread Quincey Morris
On May 29, 2016, at 19:16 , Daryle Walker  wrote:
> 
> Since I am using the substring and not including “.SubstringNotRequired”, I 
> can just remove the “guard” block, tack on a “!” to substring’s identifier, 
> and be done with it, right?

The problem is there’s no API contract that says exactly when (and when not) 
the string will be nil. I would suggest, therefore, that you don’t place any 
reliance on it not being nil in your use cases, but rather deal with it like 
this (at the top of the closure):

let substring = substring ?? ""

That is, shadow the parameter with a non-optional String variable, and assume 
an empty string when the parameter is nil. Note that the empty string will be 
either a tagged pointer or a shared global constant, so there’s no real 
performance issue in doing this. After that, you don’t care whether it was nil 
or not.

This is consistent with what would happen in Obj-C if you didn’t check for nil, 
since in Obj-C a nil pointer will appear to be an empty string in many contexts.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSDocument not displaying save prompt on dirty document

2016-05-29 Thread livinginlosangeles
Ok. The issue was that the auto-save prompt had disappeared when I was closing 
a dirty nsdocument. I added a nswindowcontroller to my nsdocument using 
addWindowController. I needed to add setShouldCloseDocument to my main 
nswindowcontroller, otherwise my document wouldn’t show the prompt.

Patrick  
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: When can String.enumerateSubstringsInRange ever pass in NIL?

2016-05-29 Thread Ken Thomases
On May 29, 2016, at 9:54 PM, Quincey Morris 
 wrote:
> 
> On May 29, 2016, at 19:16 , Daryle Walker  > wrote:
>> 
>> Since I am using the substring and not including “.SubstringNotRequired”, I 
>> can just remove the “guard” block, tack on a “!” to substring’s identifier, 
>> and be done with it, right?
> 
> The problem is there’s no API contract that says exactly when (and when not) 
> the string will be nil.

I think the documentation for SubstringNotRequired is sufficient design 
contract:

"NSStringEnumerationSubstringNotRequired
"A way to indicate that the block does not need substring, in which case nil 
will be passed. This is simply a performance shortcut."

The strong implication is that when that option is not supplied, nil will not 
be passed.  Certainly, I'd feel betrayed by the docs to discover otherwise.

Regards,
Ken

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com