Post

Replies

Boosts

Views

Activity

Reply to JSON Core Data favorites
Tell if you have any problem in doing so. A simple way to do it is to create a dictionary, with ID as key and a Bool value for favorite. Then save as UserDefaults. See a detailed example here: https ://cocoacasts. com/ud-4-how-to-store-a-dictionary-in-user-defaults-in-swift Don't forget to close the thread once solved. Good continuation.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to Problems with UILabel Constraints TopAnchor
Looks like you forgot to addSubview. Add the following at line 16:             inserateView.addSubview(address) func setUpInserateWindows(images: [UIImage], priceText: String, descriptionText: String, streetAddress: String, cityAddress: String) { var inserates = [UIView]() for image in images { let inserateView = UIView() let imageView = UIImageView() let price = UILabel() let description = UILabel() let address = UILabel() let city = UILabel() inserateView.addSubview(imageView) inserateView.addSubview(price) inserateView.addSubview(description) Note: when you paste code, please avoid all the extra empty lines which makes it more difficult to read. Use Paste and match style for pasting.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to Sorting a NSTableView in Swift
You want to implement ? optional func tableView(_ tableView: NSTableView, sortDescriptorsDidChange oldDescriptors: [NSSortDescriptor]) Could this help ? https://stackoverflow.com/questions/54595860/nstableview-better-solution-for-sorting-collection-with-nssortdescriptor
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to crash: failed to determine navigation direction for scroll
That is a problem of "conflict" between the 2 gestures. have a look here on solutions (in your case, not a TableView but CollectionView, but very similar): https://stackoverflow.com/questions/31977977/ios-uipageviewcontroller-failed-to-determine-navigation-direction Apple told me that the UIScrollViewin the UIPageViewController and the one in the UITableViewController were conflicting, causing this bug. All I did was put a UIPanGestureRecognizer on the whole view, and whenever the user scrolls up or down, the UIScrollView in the UIPageViewController is disabled, allowing the user to scroll through the UITableView without conflicts or crashing. When the user stop scrolling up or down, the UIScrollView of the UIPageViewController is re-enabled.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to Why no need of parenthesis to access nested class?
You have defined Second inside One. So, when you call One.Second(), you just create an instance of Second ("prefixed" by One). You don't have to create an instance of One. You do the same when you call from a framework:           let vc = UIKit.UIViewController() which is equivalent to           let vc2 = UIViewController() One just tells that we look for Second() inside this class.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to change user input text to Int for computation
When you have a String, you convert to num with: let str = "12" let num = Int(str) ?? 0 or let numDouble = Double(str) ?? 0.0 So, in your case, you have to get the text of the label with myLabel.text and then convert. Important to note that Int() or Double() can fail: if you pass "Hello" instead of "12", this cannot be converted to Int (or Double). Hence you get a nil value. So, result of Int() is an optional. You could unwrap with let num = Int(str)! but that is very risky: app will crash if your text is not an Int. So you can use the ?? (nil coalescing operator): if result is nil, then you give the value after ?? otherwise you unwrap (safely) and get an Int or Double (and not an optional). Don't hesitate to ask if something is not clear. Otherwise, don't forget to close the thread by marking the correct answer.
Mar ’21