Questions tagged [class-extensions]
102 questions
2
votes
1 answer
objective C explanation about categories?
in my noob mind and proceedings, when i create a category for a class, I create it in a new file
like NSArray+Shuffle.h and .m
but I have noticed that when I create for example a ViewController,
i have in the implementation:
@interface…

manuelBetancurt
- 15,428
- 33
- 118
- 216
1
vote
1 answer
What is the DRYest way to extend/patch a library in ruby?
I wonder what's the best way to write a modular extension of an existing library in ruby that alters existing methods. It should not introduce repetition of code and should be used on demand only.
The specific task I'm trying to accomplish is…

raphinesse
- 19,068
- 6
- 39
- 48
1
vote
2 answers
Does the syntax changed for class extensions?
I had code like below:
@interface InterfaceWithACategory () {
... Some variables
}
@end
Which worked perfect when compiled in XCode 4.0.2
Now I did an upgrade (already blame myself for this stupid idea) to XCode 4.2 + iOS SDK 5.0 and have an…

Artem Oboturov
- 4,344
- 2
- 30
- 48
1
vote
4 answers
Partial/Extended Class or Interface When Different Assembly Present
I use a method to handle exceptions - internally it writes to a database, but when released to the web, the source code won't include the connection string necessary to write to the database. Instead it should write to a log file.
Is it possible to…

lukiffer
- 11,025
- 8
- 46
- 70
1
vote
1 answer
Generic-type extension with a new generic type in Swift
I'd like to extend the generic type Array with a constraint on Element that depends on another generic type, such as Element == Optional.
In the case where Element is not generic, it is easy:
extension Array where Element == String…

Jean-Baptiste
- 907
- 8
- 17
1
vote
2 answers
Extension of IEnumerable's Select to include the source in the selector
One of IEnumerable's overload is:
public static IEnumerable Select(this IEnumerable source, Func selector);
In the selector I wish to include the source. I know this sounds…

pnizzle
- 6,243
- 4
- 52
- 81
1
vote
1 answer
Is there any difference between the ivar in the class interface and the ones created by declared property(modern runtime)?
In the modern runtime.
you can declare property without having the same name ivar already declared in the interface
like
@interface MyClass: NSObject
{
NSString *str2;
}
@property (retain) NSString *str1;
@property (retain) NSString…

Jimmy
- 1,094
- 10
- 22
1
vote
1 answer
kotlin class extensions resolve parent class's value instead of childs when used in list context
I'm working with class extensions in Kotlin (1.3.20), and I'm running into an issue when extending both the parent class and the child class on the same property and then using instances of those an a list.
Basically what happens is that the child…

cdx
- 99
- 8
1
vote
0 answers
How to access objective c class extension in Swift
I had many Class Extensions written before, like :
My header file, NSDate+convenience.h:
@interface NSDate (Convenience)
+ (NSDate *)dateFromMyString:(NSString *)dateString
withDateFormatStr:(NSString *)dateFormatStr;
@end
My Obj-C…

Nijat2018
- 863
- 2
- 10
- 26
1
vote
1 answer
ObjC - Why is instance allowed to access class extension property in .m file?
As is known that in ObjC property declared in .h file is the interface "visible outside", while property declared in .m file (class extension) can be only accessed in .m, kind of "private" or "hidden". But in practice code as follows can be…

刘maxwell
- 187
- 10
1
vote
1 answer
PHP Class dynamically extending in runtime
Is it possible to dynamically extend a class object in PHP? And what would be the most elegant way of doing this?
Some example code for further explanation:
class BasicClass {
private $variable;
public function BasicFunction() {
//…

Frederic Depuydt
- 13
- 6
1
vote
1 answer
Property "isEnabled" of UIBarButtonItem is an unrecognized selector in an extension of the class
In Swift 4 I want to use an extension of UIBarButtonItem that instantiates a special UIBarButtonItem object.
Here is my code (only the essential statements):
import Foundation
extension UIBarButtonItem {
convenience init(staticImageName:…

Reinhard Männer
- 14,022
- 5
- 54
- 116
1
vote
1 answer
Referring to viewcontroller outlets from viewcontroller extension
I have two view controllers SymbolsVC and ItemsVC. Both have a UIActivityIndicatorView which has been outlet by the name of spinner in each view controller like this:
class SymbolsVC: UIViewController {
@IBOutlet weak var spinner:…

Kashif
- 4,642
- 7
- 44
- 97
1
vote
2 answers
data and open incompatibility, which alternative do I have?
I am doing a kotlin port of gli and I got stuck now
Actually I have the following
open class Texture
extended by several classes such as Texture2d
Now, Texture has quite some properties
protected val storage: StorageLinear?
protected val target:…

elect
- 6,765
- 10
- 53
- 119
1
vote
1 answer
Constrained extension of generic object does not match type
I am trying to make an extension to a generic class which is constrained by the type of the generic. This is a simplification of the code I believe should work:
struct Thing {
var value: T
}
struct ContainsStringThing {
var stringThing:…

gabriellanata
- 3,946
- 2
- 21
- 27