Post

Replies

Boosts

Views

Activity

Reply to NSKeyedArchiver
Can you show a complete code to reproduce the issue? And please make your code properly formatted. As the editing feature is very limited in the def forums, you may need to use Your Answer to show additional info.
Topic: UI Frameworks SubTopic: AppKit Tags:
Nov ’21
Reply to Freeze when deallocating large data structures
It seems to be impossible to deallocate such a data structure without the Swift runtime freezing. True. Deallocating an enum instance with indirect child instances would cause deallocating the children recursively. So, when deallocating long lasting list as in your code, it would make too deep recursive calls which may result any sort of unpredictable behaviors, crashing, freezing or anything you can imagine. You may need to deallocate all the nodes in the list without consuming the native call stack -- you need non-recursive algorithm. You cannot control the deallocations of structs and enums in Swift, so you may need to make it a class and implement deinit carefully. My first trial looks like this: class ListNode { var left: ListNode? var right: ListNode? init(_ left: ListNode?, _ right: ListNode?) { self.left = left self.right = right } deinit { if left != nil || right != nil { var nodesToRelease: [ListNode] = [self] ListNode.deallocateAll(&nodesToRelease) } } private static func deallocateAll(_ nodesToRelease: inout [ListNode]) { while let top = nodesToRelease.popLast() { if let leftNode = top.left { nodesToRelease.append(leftNode) top.left = nil } if let rightNode = top.right { nodesToRelease.append(rightNode) top.right = nil } } } } var node: ListNode? = nil for _ in 0..<150_000 { node = ListNode(nil, node) } print("Done creating list") node = nil print("Completed program (this is printed within a second)") This shows Completed program (this is printed within a second) within a second. Changing 150_000 to 150_000_000, you can observe increasing of the memory consumption first, and then decreasing after Done creating list. (Takes a few minutes to finish.) I haven't tried many cases, so there may be some flaws in my code and may not be efficient. But I think my code is well explaining the problem. If you know the recursion level of the data might get hundreds or more, you should better not use enum with indirect children.
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to Can I add my app to the sharing popup menu?
Can I add my app to the sharing popup menu?  YES. You may need to add a Share Extension to your app. You can find some articles searching with "ios swift share extension". If you find some difficulty implementing your own Share Extension, many readers of this site can help if you can provide some more concrete details of your issue. (This old article of Apple may also be useful: App Extension Programming Guide.)
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to Axie
NO, at least not here. Contact to the author of the app.
Nov ’21
Reply to UIButton setBackgroundImage for different states not working
Which version of Xcode are you using? As far as I tried with buttons which I added on the storyboard with Xcode 13.1, I needed to change Style to Default to make setBackgroundImage(_:for:) effective. button1.setBackgroundImage(UIImage(named: "cardButtonSelected"), for: .normal) button1.setBackgroundImage(UIImage(named: "cardButtonUnSelected"), for: .selected) button1.isSelected = true button2.setBackgroundImage(UIImage(named: "cardButtonUnSelected"), for: .normal) button2.setBackgroundImage(UIImage(named: "cardButtonSelected"), for: .selected) button2.isSelected = true Apple introduced some big changes on UIButtons in iOS 15, many traditional codes related to UIButton would not work as before in the default settings on a new storyboard of Xcode 13.x.
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to NavigationLink Issue on Device
Thanks for updating the code. Unfortunately, I do not have a device Xs/iOS 15.1 . Tested on iPhone 12 Pro Max/iOS 15.1 Exactly the same as the updated code: ZStack enabled as I have suggested: And the latter is what I intend and is not same as first image (left). As there is no guarantee that NavigationLink with EmptyView would be shown as actually empty or not, so, I usually make them under the hood using ZStack. (In my usual apps, the hood covers whole area without transparent areas.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’21
Reply to I can't get a button to work, instead I get this error: "Accessing StateObject's object without being installed on a View. This will create a new instance each time." Help?
The WWDC 2021 session 10002 has nothing to do with your problem, using the right tags is important to get the right answers sooner. And when you show codes of View types, please show the whole code including the declaration header like struct ??????View: View {..., you are forcing readers to guess which view is used as what view... But, anyway, your problem in this case is very clear: you cannot use @StateObject somewhere else than View (or App or Scene). You may need to completely refactor your code again.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’21
Reply to I can't get a button to work, instead I get this error: "Accessing StateObject's object without being installed on a View. This will create a new instance each time." Help?
@tylerlw82, the tag thing is not a big one, please take care if you have next chance. But, in addition to @StateObject, @Environment, @FetchRequest (nor potentially @State, @EnvironmentObject) would not work in non-View context. (The runtime of SwiftUI manages them when they are in any of the views.) Please share your corrected code when done.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’21
Reply to Xcode Single Executable File in C
So can I have a single file to run and create lots of them with the tag "int main (void)" and run them? It is not clear what you mean by the tag "int main (void)", so I may be mistaking something, but with my best guess... If you want to build many executables in a single project, you may need to add a Target for each executable you want to build. In my opinion, it is easier to create as many projects as needed to build many executables. If some parts of them use exactly the same files, you can easily copy them from a project to another project.
Nov ’21
Reply to NSKeyedArchiver
Can you show a complete code to reproduce the issue? And please make your code properly formatted. As the editing feature is very limited in the def forums, you may need to use Your Answer to show additional info.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to axie infinity on testflight
This is not a place to ask TestFlight things of some specific app. Contact to the author of the app.
Replies
Boosts
Views
Activity
Nov ’21
Reply to Freeze when deallocating large data structures
It seems to be impossible to deallocate such a data structure without the Swift runtime freezing. True. Deallocating an enum instance with indirect child instances would cause deallocating the children recursively. So, when deallocating long lasting list as in your code, it would make too deep recursive calls which may result any sort of unpredictable behaviors, crashing, freezing or anything you can imagine. You may need to deallocate all the nodes in the list without consuming the native call stack -- you need non-recursive algorithm. You cannot control the deallocations of structs and enums in Swift, so you may need to make it a class and implement deinit carefully. My first trial looks like this: class ListNode { var left: ListNode? var right: ListNode? init(_ left: ListNode?, _ right: ListNode?) { self.left = left self.right = right } deinit { if left != nil || right != nil { var nodesToRelease: [ListNode] = [self] ListNode.deallocateAll(&nodesToRelease) } } private static func deallocateAll(_ nodesToRelease: inout [ListNode]) { while let top = nodesToRelease.popLast() { if let leftNode = top.left { nodesToRelease.append(leftNode) top.left = nil } if let rightNode = top.right { nodesToRelease.append(rightNode) top.right = nil } } } } var node: ListNode? = nil for _ in 0..<150_000 { node = ListNode(nil, node) } print("Done creating list") node = nil print("Completed program (this is printed within a second)") This shows Completed program (this is printed within a second) within a second. Changing 150_000 to 150_000_000, you can observe increasing of the memory consumption first, and then decreasing after Done creating list. (Takes a few minutes to finish.) I haven't tried many cases, so there may be some flaws in my code and may not be efficient. But I think my code is well explaining the problem. If you know the recursion level of the data might get hundreds or more, you should better not use enum with indirect children.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Axie Infinity ios
NO. At least, not here. Contact to the author of the app.
Replies
Boosts
Views
Activity
Nov ’21
Reply to Can I add my app to the sharing popup menu?
Can I add my app to the sharing popup menu?  YES. You may need to add a Share Extension to your app. You can find some articles searching with "ios swift share extension". If you find some difficulty implementing your own Share Extension, many readers of this site can help if you can provide some more concrete details of your issue. (This old article of Apple may also be useful: App Extension Programming Guide.)
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Axie Invitation Code
Contact to the author of the app directly. This is not a place to request sort of invitation code.
Replies
Boosts
Views
Activity
Nov ’21
Reply to Axie
NO, at least not here. Contact to the author of the app.
Replies
Boosts
Views
Activity
Nov ’21
Reply to UIButton setBackgroundImage for different states not working
Which version of Xcode are you using? As far as I tried with buttons which I added on the storyboard with Xcode 13.1, I needed to change Style to Default to make setBackgroundImage(_:for:) effective. button1.setBackgroundImage(UIImage(named: "cardButtonSelected"), for: .normal) button1.setBackgroundImage(UIImage(named: "cardButtonUnSelected"), for: .selected) button1.isSelected = true button2.setBackgroundImage(UIImage(named: "cardButtonUnSelected"), for: .normal) button2.setBackgroundImage(UIImage(named: "cardButtonSelected"), for: .selected) button2.isSelected = true Apple introduced some big changes on UIButtons in iOS 15, many traditional codes related to UIButton would not work as before in the default settings on a new storyboard of Xcode 13.x.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to NavigationLink Issue on Device
Thanks for updating the code. Unfortunately, I do not have a device Xs/iOS 15.1 . Tested on iPhone 12 Pro Max/iOS 15.1 Exactly the same as the updated code: ZStack enabled as I have suggested: And the latter is what I intend and is not same as first image (left). As there is no guarantee that NavigationLink with EmptyView would be shown as actually empty or not, so, I usually make them under the hood using ZStack. (In my usual apps, the hood covers whole area without transparent areas.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to I can't get a button to work, instead I get this error: "Accessing StateObject's object without being installed on a View. This will create a new instance each time." Help?
The WWDC 2021 session 10002 has nothing to do with your problem, using the right tags is important to get the right answers sooner. And when you show codes of View types, please show the whole code including the declaration header like struct ??????View: View {..., you are forcing readers to guess which view is used as what view... But, anyway, your problem in this case is very clear: you cannot use @StateObject somewhere else than View (or App or Scene). You may need to completely refactor your code again.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to I can't get a button to work, instead I get this error: "Accessing StateObject's object without being installed on a View. This will create a new instance each time." Help?
@tylerlw82, the tag thing is not a big one, please take care if you have next chance. But, in addition to @StateObject, @Environment, @FetchRequest (nor potentially @State, @EnvironmentObject) would not work in non-View context. (The runtime of SwiftUI manages them when they are in any of the views.) Please share your corrected code when done.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Xcode Single Executable File in C
So can I have a single file to run and create lots of them with the tag "int main (void)" and run them? It is not clear what you mean by the tag "int main (void)", so I may be mistaking something, but with my best guess... If you want to build many executables in a single project, you may need to add a Target for each executable you want to build. In my opinion, it is easier to create as many projects as needed to build many executables. If some parts of them use exactly the same files, you can easily copy them from a project to another project.
Replies
Boosts
Views
Activity
Nov ’21
Reply to UICollectionViewDiffableDataSource changes in Xcode 13
As far as I check the doc of UICollectionViewDiffableDataSource, it did not have an initializer init() even in iOS 14 SDK (Xcode 12). So, your code was using some undocumented feature and unfortunately it seemingly was working fine by luck. You may need to modify the initializer of dataSource properly.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to CAMPriorityNotificationCenter _postNotification:forEntries:
Do you have anything about the backtrace?
Replies
Boosts
Views
Activity
Nov ’21
Reply to UICollectionViewDiffableDataSource changes in Xcode 13
@surbhi_Magplus, sorry but you are not showing enough code to show something. Please show enough code which explains how you use it in multiple functions.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21