Re: Simple Swift question

2015-06-29 Thread Roland King
> On 30 Jun 2015, at 09:35, Rick Mann wrote: > > >> On Jun 29, 2015, at 16:30 , Jens Alfke wrote: >> >> The error I get with Xcode 7 beta 2 is >> >> error: operand of postfix '?' should have optional type; type is >> 'NSURLRequest' >>if let req = NSURLRequest(URL: url)? >>

Re: Simple Swift question

2015-06-29 Thread Rick Mann
> On Jun 29, 2015, at 16:30 , Jens Alfke wrote: > > The error I get with Xcode 7 beta 2 is > > error: operand of postfix '?' should have optional type; type is > 'NSURLRequest' > if let req = NSURLRequest(URL: url)? > ~~^ > > So it looks like this has

Re: Simple Swift question

2015-06-29 Thread Rick Mann
> On Jun 29, 2015, at 16:30 , Jens Alfke wrote: > > >> On Jun 29, 2015, at 4:23 PM, Rick Mann wrote: >> >> http://pastebin.com/Q7sBWBnN >> >> url is unwrapped already, and I'm (wrongly) trying to unwrap the >> NSURLRequest. But it's not complaining about the arguments to >> NSURLReque

Re: Simple Swift question

2015-06-29 Thread Jens Alfke
> On Jun 29, 2015, at 4:23 PM, Rick Mann wrote: > > http://pastebin.com/Q7sBWBnN > > url is unwrapped already, and I'm (wrongly) trying to unwrap the > NSURLRequest. But it's not complaining about the arguments to > NSURLRequest.init(URL:). The error I ge

Re: Why would scroll events not arrive?

2015-06-29 Thread Martin Wierschin
After further investigation, I've discovered what code is responsible for globally breaking scrolling my app. I have an NSScrollView subclass with the following override: - (void) scrollWheel:(NSEvent*)event { BOOL isScrollEnclosing = // YES if the receiver has scrolled to its very top/

Re: Simple Swift question

2015-06-29 Thread Rick Mann
> On Jun 29, 2015, at 16:17 , Jens Alfke wrote: > > >> On Jun 29, 2015, at 3:53 PM, Rick Mann wrote: >> >> The compiler's message was, "Could not find an overload for 'init' that >> accepts the supplied arguments." Could it instead say >> "NSURLRequst.init(URL:) does not return Optional typ

Re: Simple Swift question

2015-06-29 Thread Jens Alfke
> On Jun 29, 2015, at 3:53 PM, Rick Mann wrote: > > The compiler's message was, "Could not find an overload for 'init' that > accepts the supplied arguments." Could it instead say "NSURLRequst.init(URL:) > does not return Optional type"? The error message looks correct to me — it's complainin

Re: Swift and parameter names

2015-06-29 Thread Rick Mann
> On Jun 29, 2015, at 16:06 , Quincey Morris > wrote: > > Please stop Nice. -- Rick Mann rm...@latencyzero.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact

Re: Simple Swift question

2015-06-29 Thread Charles Srstka
On Jun 29, 2015, at 5:53 PM, Rick Mann wrote: > >> If you are using Swift 2.0, you can use the new `guard let` to get optional >> checking without the cascade of indentation. >> guard let url = NSURL(string: "") >> else { /* handle failure and either halt or return */ } >> // URL is now in

Re: Swift and parameter names

2015-06-29 Thread Quincey Morris
On Jun 29, 2015, at 15:42 , Rick Mann wrote: > > Here's an example (and this is what I frequently encounter) where requiring > parameter names adds nothing but clutter: > >let config = WKWebViewConfiguration() >self.webView = WKWebView(frame: self.webViewContainer.frame, > configuratio

Re: Swift and parameter names

2015-06-29 Thread Rick Mann
> On Jun 29, 2015, at 15:50 , Greg Parker wrote: > > Perhaps you would prefer a different whitespace convention, one with no > spaces around the colon in actual parameters. That's a popular convention in > Objective-C. Otherwise there is no difference between Objective-C and Swift > here. I

Re: Simple Swift question

2015-06-29 Thread Rick Mann
> On Jun 29, 2015, at 15:43 , Greg Parker wrote: > >> On Jun 29, 2015, at 3:18 PM, Rick Mann wrote: >> >> How are you supposed to do simple things like this, succinctly? >> >> let url = NSURL(string: "") >> let req = NSURLRequest(URL: url) >> self.webView.loadRequest(req) >> >> This, o

Re: Swift and parameter names

2015-06-29 Thread Greg Parker
> On Jun 29, 2015, at 3:42 PM, Rick Mann wrote: > > Here's an example (and this is what I frequently encounter) where requiring > parameter names adds nothing but clutter: > >let config = WKWebViewConfiguration() >self.webView = WKWebView(frame: self.webViewContainer.frame, > configur

Re: Simple Swift question

2015-06-29 Thread Rick Mann
> On Jun 29, 2015, at 15:35 , Jens Alfke wrote: > > The unsightly nesting of the if-lets can be avoided with the nifty new > ‘guard’ statement in Swift 2. Ah, yes, that's what I should be using. Thanks! -- Rick Mann rm...@latencyzero.com ___ C

Re: Simple Swift question

2015-06-29 Thread Greg Parker
> On Jun 29, 2015, at 3:18 PM, Rick Mann wrote: > > How are you supposed to do simple things like this, succinctly? > >let url = NSURL(string: "") >let req = NSURLRequest(URL: url) >self.webView.loadRequest(req) > > This, obviously, doesn't work, since the results are optionals, an

Re: Simple Swift question

2015-06-29 Thread Rick Mann
> On Jun 29, 2015, at 15:36 , Charles Srstka wrote: > > On Jun 29, 2015, at 5:18 PM, Rick Mann wrote: >> >> But it gets rapidly ridiculous with a bunch of nested if-lets (imagine you >> had more than just two operations to get from here to there). > > Have you looked at Swift 2.0 yet? It ad

Re: Swift and parameter names

2015-06-29 Thread Rick Mann
Here's an example (and this is what I frequently encounter) where requiring parameter names adds nothing but clutter: let config = WKWebViewConfiguration() self.webView = WKWebView(frame: self.webViewContainer.frame, configuration: config); If Code Completion worked 100% of the time, an

Re: Simple Swift question

2015-06-29 Thread Quincey Morris
On Jun 29, 2015, at 15:23 , Rick Mann wrote: > > Oh, I think I figured it out. NSURL(string:) is optional, but > NSURLRequest(URL:) can't. Very unexpected, and the error message I was > getting did not clue me in. > > - > > > How are you supposed to do simple things like this, succin

Re: Simple Swift question

2015-06-29 Thread Charles Srstka
On Jun 29, 2015, at 5:18 PM, Rick Mann wrote: > > But it gets rapidly ridiculous with a bunch of nested if-lets (imagine you > had more than just two operations to get from here to there). Have you looked at Swift 2.0 yet? It addresses that forced Arrow Anti-Pattern issue quite nicely. Charl

Re: Simple Swift question

2015-06-29 Thread Jens Alfke
> On Jun 29, 2015, at 3:23 PM, Rick Mann wrote: > > Oh, I think I figured it out. NSURL(string:) is optional, but > NSURLRequest(URL:) can't. Very unexpected Creating an NSURL from a string can fail, since not all strings are valid URLs. But creating an NSURLRequest isn’t failable; you always

Simple Swift question

2015-06-29 Thread Rick Mann
Oh, I think I figured it out. NSURL(string:) is optional, but NSURLRequest(URL:) can't. Very unexpected, and the error message I was getting did not clue me in. - How are you supposed to do simple things like this, succinctly? let url = NSURL(string: "") let req = NSURLRequest(U

Simple Swift question

2015-06-29 Thread Rick Mann
How are you supposed to do simple things like this, succinctly? let url = NSURL(string: "") let req = NSURLRequest(URL: url) self.webView.loadRequest(req) This, obviously, doesn't work, since the results are optionals, and so need to be unwrapped. But it gets rapidly ridiculous with

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Quincey Morris
On Jun 29, 2015, at 13:50 , Gavin Eadie wrote: > > The main thread is not involved in the above, but the idea of an > “asynchronous-that-waits” == “apparently synchronous” call is demonstrated. Yes, but you achieved that by blocking a background thread. It works because you don’t care that the

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Scott Ribe
On Jun 29, 2015, at 2:50 PM, Gavin Eadie wrote: > > The main thread is not involved in the above, but the idea of an > “asynchronous-that-waits” == “apparently synchronous” call is demonstrated. That's simply not asynchronous. -- Scott Ribe scott_r...@elevated-dev.com http://www.elevated-dev.

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Jens Alfke
> On Jun 29, 2015, at 1:50 PM, Gavin Eadie wrote: > > This is all true for a “really synchronous” call, but my suggestion is that > an “apparently synchronous” call only appears to wait; using a semaphore can > stop the return, while things keep working on other threads. I don’t think that’s

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Gavin Eadie
Somewhere in this email a lightbulb gets turned on! > On Jun 29, 2015, at 2:49 PM, Scott Ribe wrote: > > The problem is that the requirement is self-contradictory: "synchronous" > means wait, and "without impacting performance" means don't wait. While the > real requirement is probably more li

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Scott Ribe
On Jun 29, 2015, at 12:22 PM, Gavin Eadie wrote: > > Q: “Can anyone suggest a trick that allows an apparently synchronous call on > the main thread without impacting performance?” The problem is that the requirement is self-contradictory: "synchronous" means wait, and "without impacting perfor

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Gavin Eadie
> On Jun 29, 2015, at 1:19 PM, Scott Ribe wrote: > >> The problem with the callback to “after” is that “after” is just the >> continuation of the program and possibly nothing to do with what happens in >> “fakeSyncrony” .. > > Then why does it need to wait? > > This is really sounding like pr

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Jens Alfke
> On Jun 29, 2015, at 10:13 AM, Gavin Eadie wrote: > > The problem with the callback to “after” is that “after” is just the > continuation of the program and possibly nothing to do with what happens in > “fakeSyncrony” .. Yeah, I don’t think you have any alternative but to restructure your co

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Quincey Morris
On Jun 29, 2015, at 10:13 , Gavin Eadie wrote: > > I suppose the first thing “fakeSyncrony” could do is grab the address of the > next instruction and make it the address to call back to. This sounds a > little like Jens’ “crazy runtime manipulation of the stack The mechanism you describe alr

Re: Open program from custom schema link

2015-06-29 Thread Juanjo Conti
Found it Jens: func applicationWillFinishLaunching(aNotification: NSNotification?) { var appleEventManager:NSAppleEventManager = NSAppleEventManager.sharedAppleEventManager() appleEventManager.setEventHandler(self, andSelector: "handleGetURLEvent:withReplyEvent:", forEventClass: kInternetE

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Scott Ribe
On Jun 29, 2015, at 11:13 AM, Gavin Eadie wrote: > > The problem with the callback to “after” is that “after” is just the > continuation of the program and possibly nothing to do with what happens in > “fakeSyncrony” .. Then why does it need to wait? This is really sounding like program behav

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Gavin Eadie
> On Jun 29, 2015, at 12:28 PM, Scott Ribe wrote: > >> […] we have a counterexample in the form of the Canon ED-SDK, which somehow >> does accomplish this. > > I seriously doubt that. It's probably performing the work on a background > thread, > then using some callback to execute the "after"

Re: NSUserDefaults allocation size and CALayer memory usage

2015-06-29 Thread David Duncan
> On Jun 28, 2015, at 11:35 PM, Henrik Granaas-Helmers wrote: > > Hi there, > > I am new to Apple development, and new to this list. I have two questions > about memory on OS X. > > 1. NSUserDefaults seems to allocate 16 MB memory at load. I can't see myself > using a megabyte—let alone 16 o

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Michael David Crawford
Use a background task to do the real work then deliver the result on a queue. mUseba synchronous call to fetch the result from the queue or return an error result if the queue is empty. -- Michael David Crawford, Consulting Software Engineer mdcrawf...@gmail.com http://www.warplife.com/mdc/ A

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Jens Alfke
> On Jun 29, 2015, at 9:14 AM, Gavin Eadie wrote: > > Can anyone, with more knowledge than we have, suggest a trick that allows an > apparently synchronous call on the main thread without impacting performance? Not without some nasty hacks that I wouldn’t recommend. The simplest one is to run

Re: File Permissions - NSFileManager Swift

2015-06-29 Thread Jens Alfke
It always helps people answer questions if you post the exact error you get. Generally when there are mysteriously un-deletable files, it has something to do with filesystem extended attributes like ‘immutable’. You can display these by using “ls -l@“. —Jens

Re: Cheating a synchronous call on the main thread

2015-06-29 Thread Scott Ribe
On Jun 29, 2015, at 10:14 AM, Gavin Eadie wrote: > > While it seems clear to me and my friend that this in an inescapable fact of > life, we have a counterexample in the form of the Canon ED-SDK, which somehow > does accomplish this. I seriously doubt that. It's probably performing the work on

Re: NSUserDefaults allocation size and CALayer memory usage

2015-06-29 Thread Jens Alfke
> On Jun 28, 2015, at 11:35 PM, Henrik Granaas-Helmers wrote: > > 1. NSUserDefaults seems to allocate 16 MB memory at load. I can't see myself > using a megabyte—let alone 16 of those. It would be very interesting to know > why it allocates so much, and if there is a way to encourage NSUserDef

Re: Open program from custom schema link

2015-06-29 Thread Jens Alfke
> On Jun 28, 2015, at 9:59 PM, Juanjo Conti wrote: > > Is it is suppose to call MyApp with "something" as argument? How do I read > "something" from the run app? Your app delegate will be called and given the URL, although it’s been a long time since I implemented this functionality and on a q

Cheating a synchronous call on the main thread

2015-06-29 Thread Gavin Eadie
It’s standard knowledge that any operation which causes an app’s main thread to wait is bad, and that diverting such delays off the main thread allows the app to remain optimally responsive to external events. That diversion can happen via a couple of mechanisms: ‘callbacks’ (delegation and cl

Bridging CFArrayRef and NSArray

2015-06-29 Thread Dave
Hi, Is the following ok for getting a CFArrayRef and retaining it until dealloc time? Whenever refreshGlobalWindowArray is called I want the existing copy to be released and the new value to be retained. This is a Mac Project using manual memory management. All the Best Dave @property (nona

re Swift 2.0

2015-06-29 Thread Michael de Haan 
>>> var currentValue = 1 let newNewGenerator = anyGenerator { ()->Int? in let previousValue = currentValue currentValue *= 2 return ( previousValue > 20 ) ? nil : previousValue } let newGeneratedArray = Array( newNewGenerator ) For some reason you have to spe

Subclassing a Subclass of SBApplication

2015-06-29 Thread Dave
Hi, I’m using the Scripting Bridge, and I was wondering if it ok to subclass SBXXX classes. Basically, I have a header file generated by the “sdp” tool with definitions as below: And I’d like to subclass this to add some extra wrapping to hide some of the nastiness from the rest of the app and

File Permissions - NSFileManager Swift

2015-06-29 Thread Arved von Brasch
Dear Cocoa List, I’m trying to remove an application package using NSFileManager.defaultManager().removeItemAtPath(self.appPackage, error: &error) The application package was put at this location using NSFileManager.defaultManager().copyItemAtURL(pathURL as! NSURL, toURL: self.appPackage, erro

Re: NSUserDefaults allocation size and CALayer memory usage

2015-06-29 Thread Quincey Morris
On Jun 28, 2015, at 23:35 , Henrik Granaas-Helmers wrote: > > 1. NSUserDefaults seems to allocate 16 MB memory at load. I can't see myself > using a megabyte—let alone 16 of those. It would be very interesting to know > why it allocates so much, and if there is a way to encourage NSUserDefaults

Re: Swift 2.0 difficulty

2015-06-29 Thread Roland King
> On 29 Jun 2015, at 14:37, Michael de Haan  wrote: > > > Hi All > I am looking at Swift 2.0. The compiler has converted the code below to the > “latest” Swift syntax. This causes the error shown. I have spent a few days > trying to get this to compile. What is confusing to me, is that the c