Questions tagged [convenience-methods]

Convenience methods are shorthand abstractions which invoke another method by implicitly passing in default argument(s) for a common use case

Convenience methods are intended to encapsulate the verbosity of an existing API into a single expression by aliasing a method call or set of method calls with default arguments to a new method which represents a specific operation.

References

55 questions
3
votes
1 answer

New Xcode 7.3: Swift NSDate extension with nullable convenience init crashes EXC_BAD_ACCESS

I have this NSDate extension with nullable init, which worked fine all the time, until I updated to newly released Xcode 7.3. Now it crashes with EXC_BAD_ACCESS. extension NSDate { convenience init?(dateString:String, formatString:String?) …
Maris
  • 664
  • 1
  • 5
  • 15
3
votes
1 answer

Initialize subclass of NSTextView without providing NSTextContainer

I have a subclass of NSTextView, and in my initializer of this subclass I would like to call: super.init(frame: NSMakeRect(...)) which is what I always do when initializing an NSTextView programmatically. I simply write: let textView =…
3
votes
2 answers

Converting convenience methods that use Tasks

I often write code that has convenience methods which basically wrap other methods. Here's a simple example: public class WithoutAsync { public static ReadOnlyCollection GetResponses(IEnumerable fromRequests) { var…
rory.ap
  • 34,009
  • 10
  • 83
  • 174
3
votes
1 answer

Making a library of libraries so that the end user doesn't require the original libraries

I am making a library using C++ 11, and my library uses several other libraries, like FreeImage and GLFW. I would like to be able to distribute my library in a way that the end users will not be required to install the other libraries; this will…
3
votes
3 answers

Prefer non-member non-friend functions... in Java?

Disclaimer: this question is directed as those who would consider Scott Meyers' advice in Item 23 of Effective C++ to be good OO design -- at least in C++. In Java, where global functions do not exist, it might seem at first that this principle…
Joseph Thomson
  • 9,888
  • 1
  • 34
  • 38
2
votes
1 answer

Convenience initialiser keeps crashing however designated initialiser works fine?

When creating an instance using the convenience initialiser the playground keeps giving me this error "error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=2, address=0x7ffee5ae9ff8)" however when using the designated initialiser it works…
2
votes
1 answer

Should I declare methods for developers convenience in an interface?

We recently had a discussion about defining methods for developers convenience in interfaces. Given the following minimal example: public interface aInterface{ public void setUri(Uri uri); public void setUri(String uri); } public class…
martin
  • 2,957
  • 3
  • 25
  • 46
2
votes
2 answers

When writing a large app in Swift, do I even need to use the "init" method at all?

This is more of a concept question. Why bother with using init? class Person { var name:String var height:Double ... init(name: String) { self.name = name self.height:Double ... } Why…
2
votes
2 answers

Developing Yesod application with faster feedback (interpretation mode)?

When I use yesod devel it just recompiles whole application every time I change template file or any module. Is there any way to get faster feedback on development? I mean do not recompile, but use ghci or something with Yesod?
s9gf4ult
  • 862
  • 6
  • 20
2
votes
1 answer

Autorelease in Objective C and Convenience Methods

So I am a bit confused on when objects are autoreleased. I understand so far that if I am not the "owner", it will do so. But in which cases would I not be the owner? When I create an object using a convenience method? I don't understand where all…
2
votes
3 answers

Convenience function for exporting objects to the global environment

UPDATE: I have added a variant of Roland's implementation to the kimisc package. Is there a convenience function for exporting objects to the global environment, which can be called from a function to make objects available globally? I'm looking…
krlmlr
  • 25,056
  • 14
  • 120
  • 217
1
vote
2 answers

subclassing convenience construtctor

If I have a super class with a convenience constructor as follows (using ARC): +(id)classA { ClassA *foo = [[ClassA alloc] init]; return foo; } If I then subclass ClassA, with a class named ClassB, and I want to override the convenience…
Wise Shepherd
  • 2,228
  • 4
  • 31
  • 43
1
vote
4 answers

On lazy instantiation and convenience methods

Assume you have a Singleton Constants class, instance of which you'd like to use throughout your application. In someClass, therefore we can reference [Constants instance] someCleverConstant]; Typing this gets old really quick and it would be nice…
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
1
vote
0 answers

Expose a Swift convenience initializer as an Objective-C factory constructor

I'm trying to make the new Swift version of a library source-compatible with the legacy Objective-C version of the library. I know that if an Objective-C convenience initializer and Objective-C factory constructor both take the same argument, only…
Frank Schmitt
  • 25,648
  • 10
  • 58
  • 70
1
vote
1 answer

Convenience vs multiple inits Swift

I have read responses to similar questions here, but I am still puzzled regarding what would be the best implementation here, why, and is there any difference. In this implementation, I have two initializers for the class class Person1 { var name:…
Stewart Lynch
  • 875
  • 9
  • 26