Post

Replies

Boosts

Views

Activity

How to subclass NSLocale for tests
I want to unit test some Swift classes which would take Locale as a parameter and then behave in locale-specific way. It looks like there is no easy way to provide my own locale implementation though. I'd like to avoid swizzling, so I tried to subclass NSLocale, i.e.: class MyLocale: NSLocale { init(myargs: whatever) { // initialize here super.init(localeIdentifier: "C") } } but this crashes in runtime:  -[NSLocale initWithLocaleIdentifier:]: method only defined for abstract class. So I re-define that initializer: class MyLocale: NSLocale { override init(localeIdentifier string: String) { // initialize here super.init(localeIdentifier: string) // putting super.init() here doesn't help either } } but the result is the same: but this crashes in runtime:  -[NSLocale initWithLocaleIdentifier:]: method only defined for abstract class. is there any way to properly do what I want without resorting to Objective-C runtime and method swizzling?
2
0
1.1k
Sep ’21
Async/await pattern and stack size
According to this: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html backgroud thread stack size for background threads is 512KB. When using plain old NSThread one control this by using NSThread.stackSize property ( https://developer.apple.com/documentation/foundation/thread/1415190-stacksize ). Is it possible to indicate that asyncDetached {} task requires more stack space than system allocates to background threads by default?
0
0
1k
Jun ’21
How to subclass NSLocale for tests
I want to unit test some Swift classes which would take Locale as a parameter and then behave in locale-specific way. It looks like there is no easy way to provide my own locale implementation though. I'd like to avoid swizzling, so I tried to subclass NSLocale, i.e.: class MyLocale: NSLocale { init(myargs: whatever) { // initialize here super.init(localeIdentifier: "C") } } but this crashes in runtime:  -[NSLocale initWithLocaleIdentifier:]: method only defined for abstract class. So I re-define that initializer: class MyLocale: NSLocale { override init(localeIdentifier string: String) { // initialize here super.init(localeIdentifier: string) // putting super.init() here doesn't help either } } but the result is the same: but this crashes in runtime:  -[NSLocale initWithLocaleIdentifier:]: method only defined for abstract class. is there any way to properly do what I want without resorting to Objective-C runtime and method swizzling?
Replies
2
Boosts
0
Views
1.1k
Activity
Sep ’21
Async/await pattern and stack size
According to this: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html backgroud thread stack size for background threads is 512KB. When using plain old NSThread one control this by using NSThread.stackSize property ( https://developer.apple.com/documentation/foundation/thread/1415190-stacksize ). Is it possible to indicate that asyncDetached {} task requires more stack space than system allocates to background threads by default?
Replies
0
Boosts
0
Views
1k
Activity
Jun ’21