Singleton or class methods?

2014-09-13 Thread Trygve Inda
I have a project that involves several different targets.

Included in all this is a set of related utility methods that need to be
used by different sections of the code. I am wondering how is the best way
to do this so that I don't have the same utility methods written in
different places.

1. I could make a class MyUtilities that consisted of the 10 or so methods
as class methods and the class would have no instance methods or instance
variables.

2. I could make a singleton that put the methods as instance methods, but
also had no instance variables.

Thoughts?

I can't really make these methods a category on anything else.

These methods are used to convert between an NSScreen, CGDirectDisplayID,
io_service_t, and a few other ways of dealing with screen identification. So
a category on NSScreen is not going to work since in some cases an NSScreen
is not known/used.

Trygve




___

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: Singleton or class methods?

2014-09-13 Thread ChanMaxthon
Why not use straight C functions?

Sent from my iPad

 On Sep 13, 2014, at 20:45, Trygve Inda cocoa...@xericdesign.com wrote:
 
 I have a project that involves several different targets.
 
 Included in all this is a set of related utility methods that need to be
 used by different sections of the code. I am wondering how is the best way
 to do this so that I don't have the same utility methods written in
 different places.
 
 1. I could make a class MyUtilities that consisted of the 10 or so methods
 as class methods and the class would have no instance methods or instance
 variables.
 
 2. I could make a singleton that put the methods as instance methods, but
 also had no instance variables.
 
 Thoughts?
 
 I can't really make these methods a category on anything else.
 
 These methods are used to convert between an NSScreen, CGDirectDisplayID,
 io_service_t, and a few other ways of dealing with screen identification. So
 a category on NSScreen is not going to work since in some cases an NSScreen
 is not known/used.
 
 Trygve
 
 
 
 
 ___
 
 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/xcvista%40me.com
 
 This email sent to xcvi...@me.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: Singleton or class methods?

2014-09-13 Thread Ken Thomases
On Sep 13, 2014, at 7:45 AM, Trygve Inda cocoa...@xericdesign.com wrote:

 These methods are used to convert between an NSScreen, CGDirectDisplayID,
 io_service_t, and a few other ways of dealing with screen identification. So
 a category on NSScreen is not going to work since in some cases an NSScreen
 is not known/used.

A category can add class methods.

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

Re: Singleton or class methods?

2014-09-13 Thread Alex Zavatone
I use a singleton for variable storage, a utility class for methods I want to 
call from anywhere and everywhere.  

On Sep 13, 2014, at 8:45 AM, Trygve Inda wrote:

 I have a project that involves several different targets.
 
 Included in all this is a set of related utility methods that need to be
 used by different sections of the code. I am wondering how is the best way
 to do this so that I don't have the same utility methods written in
 different places.
 
 1. I could make a class MyUtilities that consisted of the 10 or so methods
 as class methods and the class would have no instance methods or instance
 variables.
 
 2. I could make a singleton that put the methods as instance methods, but
 also had no instance variables.
 
 Thoughts?
 
 I can't really make these methods a category on anything else.
 
 These methods are used to convert between an NSScreen, CGDirectDisplayID,
 io_service_t, and a few other ways of dealing with screen identification. So
 a category on NSScreen is not going to work since in some cases an NSScreen
 is not known/used.
 
 Trygve
 
 
 
 
 ___
 
 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/zav%40mac.com
 
 This email sent to z...@mac.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: Singleton or class methods?

2014-09-13 Thread Jens Alfke
I would go with class methods. Apple's APIs tend to use instance methods 
(NSFileManager, NSNotificationCenter, etc.); the benefit of those is that you 
can have multiple instances with different state (like delegates), or different 
behaviors. The doesn't seem like it's relevant to your case, though, and it's 
nice to be able to avoid to write sharedInstance all the time.

Straight C functions work too; I also use those for things like this. Pros: 
they're faster. Cons: the call site is less descriptive.

—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