Post

Replies

Boosts

Views

Activity

Reply to Advice needed on passing Count of records in rendered Mapview in Second View Controller to be displayed in First View Controller
What is the best way for the First View Controller to retrieve the count from the rendered map in the Second View Controller so that the count is displayed on the Dashboard to the User upon launching the App? It is hard to say what would the best for your app, as it depends on the details of your view controllers. So, this is just one example, but you can use sort of shared data container. Something like this: class DataContainer { static let shared = DataContainer() var countOfRecords: Int = 0 //... } class FirstViewController: UIViewController { let dataContainer = DataContainer.shared func someMethod() { let count = dataContainer.countOfRecords //... } } class SecondViewController: UIViewController { let dataContainer = DataContainer.shared func someAction() { //... dataContainer.countOfRecords = ... } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21
Reply to Changing a fetch request
Thanks for showing your code. It would be better if it were properly formatted. (As the editing feature is limited in this site, you may need to add an answer to show additional info to your question.) Anyway, I will look into it when I'm ready.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21
Reply to Resources for getting started
You may find many resources to learn app development in Swift with Xcode, but Apple's books may be a good starting point. Swift Development Resources Check Intro to App Development with Swift or App Development with Swift. Unfortunately, the books may not be up-to-date, and you may find some difficulties to work with it using the latest Xcode. But the core part of them are very fine and can be a good help learning app development. And this site, the dev forums, would be a great help when you cannot solve some issues by yourself.
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’21
Reply to Changing a fetch request
Your code is incomplete, so I cannot test, but can you try something like this: struct EditSocialView: View { @Environment(\.managedObjectContext) var managedObjectContext @Environment(\.presentationMode) var presentationMode var lodge: Lodge = getLodgeData() @State var lodgeId = -1 var body: some View { //... EditSocialList(lodgeId: lodgeId) .onAppear(perform: { self.lodgeId = lodge.id }) //... } } struct EditSocialList: View { var lodgeId: Int //this gets the list @FetchRequest var cdlodges: FetchedResults<CDLodge> init(lodgeId: Int) { self.lodgeId = lodgeId self._cdlodges = FetchRequest( entity: CDLodge.entity(), sortDescriptors: [ NSSortDescriptor(keyPath: \CDLodge.lodge, ascending: true), ], predicate: NSPredicate(format: "lodgeid == \(lodgeId)") ) } var body: some View { //use `cdlodges` here... } } With separating the parts depending on FetchedResults, you may be able to initialize the FetchRequest using lodgeId.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21
Reply to Sharesheet and iPads
Have you tried this: activityViewController.popoverPresentationController?.sourceView = sender (Assuming sender is a UIButton.) Seems iPadOS cannot find where to show the share sheet when you specify the whole view. By the way, you should better use Code Block rather than Text attachment when you show a code not too long.
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’21
Reply to Check on FetchRequest not working
I tried putting the check after the request Seems you put the check after initializing FetchRequest, not after the request. It is hard to predict when exactly the request is made or when the result is updated. One possible solution would be like this: struct TestViewPage: View { var lodgeid: Int @Environment(\.managedObjectContext) var managedObjectContext var lodge: Lodge = getLodgeData() var favourite: Bool {!cdlodges.isEmpty} //<- //this gets the list @FetchRequest var cdlodges: FetchedResults<CDLodge> init(lodgeid: Int) { self.lodgeid = lodgeid self._cdlodges = FetchRequest( entity: CDLodge.entity(), sortDescriptors: [ NSSortDescriptor(keyPath: \CDLodge.lodge, ascending: true), ], predicate: NSPredicate(format: "lodgeid == \(lodgeid)") ) } var body: some View { NavigationView { ScrollView { VStack(alignment: .leading) { VStack { switch favourite { case false: Button(action: { ///save the lodge in core data //... }) { Image("favicon_off") } case true: Button(action: { ///delete the lodge from Core Data //... }) { Image("favicon_on") } } } } .padding() }///end of scrollview .navigationBarTitle("") .navigationBarHidden(true) } //end of navigationview } } With checking favourite dynamically, you would get the result you want. (Though, I omitted favourite = setFav(), which I cannot guess what you want to do with it...)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21
Reply to Is C similar to Objective-c ?
will learning Objective-c be easy considering that I know C? Syntactically, Objective-C is an extension of C. So, some portion of Objective-C is exactly the same as C. Your experience of C would help learning such aspect of Objective-C. But the core part of Objective-C programming is made of Object Oriented class system, which you cannot find in C. If you do not have any knowledge about Object Oriented Programming, you may find hard difficulties in that part. If you have some knowledge about Smalltalk, it would help understanding OOP parts of Objective-C. Or if you know some OOP languages, such as Java or C#, that would also help learning Objective-C. Conclusion, your knowledge of C would help learning Objective-C, but whether it is easy or not would depend on your other experiences or your way of thinking.
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’21
Reply to ProgressView Error
As far as I tried, your code shown did not cause the issue you described. (I needed to fill the first line import SwiftUI, but that had nothing to do with the error, I think.) Sometimes, Xcode might show some old bugs which was fixed already. Have you tried Clean Build Folder (Shift-Cmd-K) ? (Or you can choose it from Product menu.)
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’21
Reply to Can not ForEach Int Array in Dictionary
Many things may affect the error compiler cannot type check the expression. Can you show a complete code to reproduce the issue?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Advice needed on passing Count of records in rendered Mapview in Second View Controller to be displayed in First View Controller
Are you really using SwiftUI? If you are working with Storyboard and view controllers, you may be using UIKit, not SwiftUI.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Back button removed in the navigation bar once the view loads
If you would like to enhance the chance to be helped, you should better show your code rather than a video. Create a project, simplified but enough to reproduce the issue, and show all the code in the project.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Advice needed on passing Count of records in rendered Mapview in Second View Controller to be displayed in First View Controller
Thanks for clarification. You should better use the right tags, that would help you get the better responses sooner.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Advice needed on passing Count of records in rendered Mapview in Second View Controller to be displayed in First View Controller
What is the best way for the First View Controller to retrieve the count from the rendered map in the Second View Controller so that the count is displayed on the Dashboard to the User upon launching the App? It is hard to say what would the best for your app, as it depends on the details of your view controllers. So, this is just one example, but you can use sort of shared data container. Something like this: class DataContainer { static let shared = DataContainer() var countOfRecords: Int = 0 //... } class FirstViewController: UIViewController { let dataContainer = DataContainer.shared func someMethod() { let count = dataContainer.countOfRecords //... } } class SecondViewController: UIViewController { let dataContainer = DataContainer.shared func someAction() { //... dataContainer.countOfRecords = ... } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Changing a fetch request
Can you show your code?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Changing a fetch request
Thanks for showing your code. It would be better if it were properly formatted. (As the editing feature is limited in this site, you may need to add an answer to show additional info to your question.) Anyway, I will look into it when I'm ready.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Resources for getting started
You may find many resources to learn app development in Swift with Xcode, but Apple's books may be a good starting point. Swift Development Resources Check Intro to App Development with Swift or App Development with Swift. Unfortunately, the books may not be up-to-date, and you may find some difficulties to work with it using the latest Xcode. But the core part of them are very fine and can be a good help learning app development. And this site, the dev forums, would be a great help when you cannot solve some issues by yourself.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Changing a fetch request
Your code is incomplete, so I cannot test, but can you try something like this: struct EditSocialView: View { @Environment(\.managedObjectContext) var managedObjectContext @Environment(\.presentationMode) var presentationMode var lodge: Lodge = getLodgeData() @State var lodgeId = -1 var body: some View { //... EditSocialList(lodgeId: lodgeId) .onAppear(perform: { self.lodgeId = lodge.id }) //... } } struct EditSocialList: View { var lodgeId: Int //this gets the list @FetchRequest var cdlodges: FetchedResults<CDLodge> init(lodgeId: Int) { self.lodgeId = lodgeId self._cdlodges = FetchRequest( entity: CDLodge.entity(), sortDescriptors: [ NSSortDescriptor(keyPath: \CDLodge.lodge, ascending: true), ], predicate: NSPredicate(format: "lodgeid == \(lodgeId)") ) } var body: some View { //use `cdlodges` here... } } With separating the parts depending on FetchedResults, you may be able to initialize the FetchRequest using lodgeId.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Sharesheet and iPads
Have you tried this: activityViewController.popoverPresentationController?.sourceView = sender (Assuming sender is a UIButton.) Seems iPadOS cannot find where to show the share sheet when you specify the whole view. By the way, you should better use Code Block rather than Text attachment when you show a code not too long.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Check on FetchRequest not working
I tried putting the check after the request Seems you put the check after initializing FetchRequest, not after the request. It is hard to predict when exactly the request is made or when the result is updated. One possible solution would be like this: struct TestViewPage: View { var lodgeid: Int @Environment(\.managedObjectContext) var managedObjectContext var lodge: Lodge = getLodgeData() var favourite: Bool {!cdlodges.isEmpty} //<- //this gets the list @FetchRequest var cdlodges: FetchedResults<CDLodge> init(lodgeid: Int) { self.lodgeid = lodgeid self._cdlodges = FetchRequest( entity: CDLodge.entity(), sortDescriptors: [ NSSortDescriptor(keyPath: \CDLodge.lodge, ascending: true), ], predicate: NSPredicate(format: "lodgeid == \(lodgeid)") ) } var body: some View { NavigationView { ScrollView { VStack(alignment: .leading) { VStack { switch favourite { case false: Button(action: { ///save the lodge in core data //... }) { Image("favicon_off") } case true: Button(action: { ///delete the lodge from Core Data //... }) { Image("favicon_on") } } } } .padding() }///end of scrollview .navigationBarTitle("") .navigationBarHidden(true) } //end of navigationview } } With checking favourite dynamically, you would get the result you want. (Though, I omitted favourite = setFav(), which I cannot guess what you want to do with it...)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to SwiftUI beginner stuck on a code roadblock
You should better try to explain what you want to do more clearly. Showing more code and/or explaining with examples would help. And please use Code Block feature when showing codes. Also you should show which line and the detailed message when talking about errors.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Is C similar to Objective-c ?
will learning Objective-c be easy considering that I know C? Syntactically, Objective-C is an extension of C. So, some portion of Objective-C is exactly the same as C. Your experience of C would help learning such aspect of Objective-C. But the core part of Objective-C programming is made of Object Oriented class system, which you cannot find in C. If you do not have any knowledge about Object Oriented Programming, you may find hard difficulties in that part. If you have some knowledge about Smalltalk, it would help understanding OOP parts of Objective-C. Or if you know some OOP languages, such as Java or C#, that would also help learning Objective-C. Conclusion, your knowledge of C would help learning Objective-C, but whether it is easy or not would depend on your other experiences or your way of thinking.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to ProgressView Error
As far as I tried, your code shown did not cause the issue you described. (I needed to fill the first line import SwiftUI, but that had nothing to do with the error, I think.) Sometimes, Xcode might show some old bugs which was fixed already. Have you tried Clean Build Folder (Shift-Cmd-K) ? (Or you can choose it from Product menu.)
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Local notifications
Do you know how to do it when if is not needed?
Replies
Boosts
Views
Activity
Jun ’21