304 questions
1 vote
1 answer
311 views
How to create a macro in Swift that doesn’t return a value but simply substitutes code for execution?
I want to create a Swift macro that doesn’t return a value to be inserted somewhere; I want a macro that simply substitutes code in its place. Specifically, I want to avoid constantly repeating the ...
1 vote
1 answer
80 views
Creating generics with delegate protocol type
I am trying to refactor this code: @objc protocol BaseDelegate { func xxx() } protocol DerivedDelegate: BaseDelegate { func yyy() } protocol NextDerivedDelegate: BaseDelegate { func zzz()...
1 vote
1 answer
237 views
if self in dispatch_source_set_event_handler need to be weak
I got a timer for uploading logs,here is the code: - (void)setupTimer { if (_timerForRecording) { dispatch_source_cancel(_timerForRecording); _timerForRecording = NULL; } ...
0 votes
2 answers
513 views
How to test an object is deallocated?
I have some mock code that performs a retain cycle (or at least in my mind it should). Here it is: protocol MyService { func perform(completion: @escaping () -> Void) } class MyServiceImpl: ...
0 votes
1 answer
136 views
enum stores data remains stored in the static variable of an enumeration even if the view controller dismisses
I have a problem and do not know what to do. My FirstViewController calls with let secondVC = SecondViewController() let navController = UINavigationController(rootViewController: secondVC) ...
3 votes
2 answers
1k views
Weak reference doesn't work as expected when passing it as a method reference
I am already aware of the strong/weak reference concept in swift. yet after running the next code, and tapping on the Button (and dismissing the screen), the TestViewModel stayed in memory! I was ...
1 vote
1 answer
1k views
SwiftUI List memory leak
Here is a very simple code example that reproduces a memory leak when deleting an item in SwiftUI List. This is reproducible on iOS 15 and iOS 16 (at least). Item's are never deallocated even if they ...
0 votes
0 answers
74 views
How to avoid retain cycle when assigning NSDocument as NSViewController's representedObject
I am building a macOS Document based application. I am following Apple's example code, which can be found here. In Apple's example, the NSDocument assigns itself as the NSViewController's ...
0 votes
2 answers
577 views
Memory leak situation when storing a URLSession task in a property in Swift
I'm trying to understand the memory leak situation in Swift language but there is a situation that I'm still wondering. I've created a new UIViewController and call fetch function with storing the ...
0 votes
1 answer
88 views
Why does this NOT leak memory? RxFeedback
class ViewModel { ... func state(with bindings: @escaping (Driver<State>) -> Signal<Event>) -> Driver<State> { Driver.system( initialState: .initial, ...
0 votes
1 answer
342 views
Do you need unowned or weak inside a UIAlertController handler which captures self?
Does a UIAlertAction's handler need a [weak self] or [unowned self] to avoid a retain cycle, or is it fine to keep it as a strong reference? e.g. extension UIViewController { func showAlert() { ...
2 votes
0 answers
144 views
SwiftUI retain cycle with class
I have a View which contains some kind of a controller. I need to have ability to trigger View's method from the controller. But I am getting retain cycle that I can't solve. Such View never destroy ...
0 votes
0 answers
780 views
How to resolve "AttributeGraph: cycle" warnings in the following code?
For context, the goal of the code below is to intercept a particular type of link inside a webview and handle navigation across a tabview natively (to a separate webview displaying the desired page) ...
0 votes
1 answer
70 views
UIVIewController Not Getting Deinitialized When Popping
I am building a settings screen in an app where I have a list of cells. If a user taps on a cell it pushes another controller onto the stack. However, I have this flow in several places in my app. ...
0 votes
1 answer
526 views
How to use Xcode static analyzer command line to generate an HTML report of warnings?
I installed llvm and use scan-build to statically analyze a very simple demo project. In this project, I intentionally created a retain cycle and Xcode can immediately display a retain cycle warning ...