Get file argument

2016-09-04 Thread Andreas Falkenhahn
When double-clicking a document file that is to be opened with my app,
the path to this file isn't passed in argv[] but can be obtained by 
implementing "openFile" in the NSApplicationDelegate.

Is there also a way to get the file argument without having an NSApp,
i.e. can my program somehow obtain the file argument *before* creating
the NSApp object or is that impossible?

-- 
Best regards,
 Andreas Falkenhahn  mailto:andr...@falkenhahn.com

___

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: Get file argument

2016-09-04 Thread Jens Alfke

> On Sep 4, 2016, at 4:56 AM, Andreas Falkenhahn  wrote:
> 
> Is there also a way to get the file argument without having an NSApp,
> i.e. can my program somehow obtain the file argument *before* creating
> the NSApp object or is that impossible?

Perhaps through LaunchServices, or by implementing its own AppleEvent handler 
for the ‘odoc’ event.

I do still feel that your attempt to build this 3rd-party code wrapper by 
avoiding the normal Cocoa application/event loop is a mistake. You’re going to 
run into one problem after another by going completely against the grain of the 
framework like this.

—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: Get file argument

2016-09-04 Thread Jean-Daniel Dupas

> Le 4 sept. 2016 à 20:48, Jens Alfke  a écrit :
> 
> 
>> On Sep 4, 2016, at 4:56 AM, Andreas Falkenhahn  
>> wrote:
>> 
>> Is there also a way to get the file argument without having an NSApp,
>> i.e. can my program somehow obtain the file argument *before* creating
>> the NSApp object or is that impossible?
> 
> Perhaps through LaunchServices, or by implementing its own AppleEvent handler 
> for the ‘odoc’ event.
> 
> I do still feel that your attempt to build this 3rd-party code wrapper by 
> avoiding the normal Cocoa application/event loop is a mistake. You’re going 
> to run into one problem after another by going completely against the grain 
> of the framework like this.
> 

Whatever you do, you still have to pull the incoming events, else you Apple 
Event won’t be dispatched. As the canonical way to do that is though NSApp, I 
don’t now if this is possible.



___

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: Get file argument

2016-09-04 Thread Andreas Falkenhahn
On 04.09.2016 at 20:48 Jens Alfke wrote:



> On Sep 4, 2016, at 4:56 AM, Andreas Falkenhahn  wrote:

> Is there also a way to get the file argument without having an NSApp,
> i.e. can my program somehow obtain the file argument *before* creating
> the NSApp object or is that impossible?



> Perhaps through LaunchServices

Any pointers? I don't see anything that could help me here but that document is
quite confusing anyway with so many things deprecated...

> I do still feel that your attempt to build this 3rd-party code
> wrapper by avoiding the normal Cocoa application/event loop is a
> mistake. You’re going to run into one problem after another by going
> completely against the grain of the framework like this.

Don't worry, I'm pretty much done already and it's working fine. 
And I'm not the only one who is using a custom solution. Check out
popular toolkits like SDL, GLFW, wxWidgets... they all do it one or
another. And even Apple says that it's legit:

"Override run if you want the app to manage the main event loop differently
than it does by default. (This a critical and complex task, however, that you
should only attempt with good reason.)"

I just wish there'd be some more information on how exactly this "critical
and complex task" should be implemented in practice ;)

-- 
Best regards,
 Andreas Falkenhahnmailto:andr...@falkenhahn.com


___

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

Init in Swift

2016-09-04 Thread Gerriet M. Denkmann
I have a SuperClass with several Subclasses.
The SuperClass will never be instantiated. It just contains code common to all 
subclasses.

Here an example:
I really want “onlyKnownBySubclass” to be a constant (i.e. let instead of var). 
But cannot figure out  how to do this.

class SuperClass
{
let knownBySuperclass: Int
var onlyKnownBySubclass: Int//  this is a constant, only set in 
SubClass.init

init(some: Int)
{
knownBySuperclass = some * 2
onlyKnownBySubclass = 0 //  this value will never be used
}

final func someFunction() -> Void
{
print("Should never be zero: \(onlyKnownBySubclass)")
}
}

final class SubClass: SuperClass
{
override init(some: Int)
{
super.init(some: some)

//  depends on knownBySuperclass:
onlyKnownBySubclass = knownBySuperclass + 5 //  
constant - will never change after this
}
}

let a = SubClass(some:11)
a.someFunction()//  prints: “Should never be zero: 27”

Gerriet.


___

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: Init in Swift

2016-09-04 Thread Quincey Morris
On Sep 4, 2016, at 22:50 , Gerriet M. Denkmann  wrote:
> 
> I really want “onlyKnownBySubclass” to be a constant (i.e. let instead of var)

There’s an easy way if you can declare both classes in the same file. Then, you 
can just declare the instance variable like this:

>   private(set) var onlyKnownBySubclass: Int


(That’s Swift 2. For Swift 3, use “fileprivate” instead of “private”.) In this 
case, “onlyKnownBySubclass” looks like a “let” property outside that one source 
file.

If you can’t do that, you can do it with a closure, assuming the places of 
definition aren’t more complicated than in your code. Something like this:

> class SuperClass
> {
>   let knownBySuperclass: Int
>   let onlyKnownBySubclass: Int
>   
>   init(some: Int, calc: (known: Int) -> Int)
>   {
>   knownBySuperclass = some * 2
>   onlyKnownBySubclass = calc (known: knownBySuperclass)
>   }
>   
>   final func someFunction() -> Void
>   {
>   print("Should never be zero: \(onlyKnownBySubclass)")
>   }
> }
> 
> final class SubClass: SuperClass
> {
>   init(some: Int)
>   {
>   super.init(some: some) { $0 + 5 }
>   }
> }
> 
> let a = SubClass(some:11)
> a.someFunction()  //  prints: “Should never be zero: 27”

This closure “{ $0 + 5 }” is shorthand for the longer form:

{ 
valuePassed in 
return valuePassed + 5 
}

The idea is that the superclass contributes values by parameters to the closure 
(just one, knownBySuperclass, in this case), and the subclass contributes the 
rest of the expression (which could make use of other subclass properties, 
since this closure occurs after the property initialization phase of the 
subclass init.

More globally, this sort of thing is not terribly idiomatic for Swift, because 
you’re trying to hide things that could get exposed other ways, for example, by 
“hostile” subclassing. The Swift-ier way would be to use a protocol instead of 
(or in addition to, but preferably instead of) the superclass. The protocol 
would “force” the subclass to define its own “onlyKnownBySubclass” locally.

___

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