Post

Replies

Boosts

Views

Activity

Reply to Apple Safari Extension
Did you read that ? https://developer.apple.com/documentation/safariservices/safari_web_extensions/managing_safari_web_extension_permissions https://developer.apple.com/documentation/safariservices/safari_app_extensions/safari_app_extension_info_property_list_keys/adjusting_website_access_permissions
Topic: Safari & Web SubTopic: General Tags:
Nov ’21
Reply to Resetting a NSPredicate
So, you checked that searchFieldDidEndSearching is called ? func searchFieldDidEndSearching(_ sender: NSSearchField) {         print("V&G_Project___TrackListView searchFieldDidEndSearching : ", self)         arrayController.filterPredicate = nil     } But how could arrayController.filterPredicate be set to nil ? Is filterPredicate really an optional ? Where do you call _filterTracks ?
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to Open Multiple VCs from Cells in Table View
You do not yell how your cell type is defined. Is it a subclass of UITableViewCell ? Or a plain UITableViewCell ? I assume you have defined a subclass to have specific properties, as name. You could do in several ways: Create as many segues (from the VC itself) to the different destinations (route1_vc, route2_vc…) and use them: func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){ tableView.deselectRow(at: indexPath, animated: true) if let cell = tableView.cellForRow(at: indexPath) as? YourCellType { switch cell.name { case "one": performSegue(withIdentifier: "1", sender: self) case "two": performSegue(withIdentifier: "2", sender: self) default: break } } } //Here I can perform just one VC form all cells, I need each cell to open each VC (cell with name "one" opens "route1_vc"; cell with name "two" opens "route2_vc" etc.) Go directly to the VC: func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){ tableView.deselectRow(at: indexPath, animated: true) if let cell = tableView.cellForRow(at: indexPath) as? YourCellType { let storyboard = UIStoryboard(name: "Main", bundle: nil) var destViewController : UIViewController? switch cell.name { case "one": destViewController = storyboard.instantiateViewController(withIdentifier: "route1_vc") case "two": destViewController = storyboard.instantiateViewController(withIdentifier: "route2_vc") default: return } if destViewController != nil { self.present(destViewController!, animated: true, completion: nil) } } } //Here I can perform just one VC form all cells, I need each cell to open each VC (cell with name "one" opens "route1_vc"; cell with name "two" opens "route2_vc" etc.)
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21
Reply to Function returns an empty array but the same function can return a filled NSMenu
Problem is that you return submenu immediately, before any item has been added: line 6 dispatches to a thread then code continues immediately at line 38, where subMenu is not yet filled 1. func laodRss(outline: Outline, subMenu: NSMenu) -> NSMenu { 2. var articleList = [NSMenuItem] () 3. 4. let url = URL(string: outline.xmlUrl)! 5. 6. AF.request(url).responseRSS() { (response) -> Void in 7. if let feed: RSSFeed = response.value { 8. for item in feed.items { 9. let article = NSMenuItem() 10. let timeString = self.formatDate(item: item) 11. if timeString != "" { 12. var title = self.shortenText(item: item.title!) 13. title = title + " " + timeString 14. 15. let someObj: NSString = item.link! as NSString 16. article.representedObject = someObj 17. article.action = #selector(self.openBrowser(urlSender:)) 18. article.title = title 19. 20. //// Get the url from the article and add /favicon.ico to get the image 21. //// Will add the image to each article to indicate the source 22. let url = URL(string: outline.icon) 23. 24. self.getData(from: url!) { data, response, error in 25. guard let data = data, error == nil else { return } 26. 27. 28. DispatchQueue.main.async() { [weak self] in 29. article.image = NSImage(data: data) 30. article.image?.size = CGSize(width: 15, height: 15) 31. } 32. } 33. subMenu.addItem(article) 34. } 35. } 36. } 37. } 38. return subMenu 39. } You have a few ways to correct this: for a very quick test, add a sleep(20) just before line 38. But that's just for test, not a solution for real app. use semaphore, to make sure all operations requests are completed use completion handler or, with iOS 15, use await/async For completion handler, should be like this (sorry, I could not test in app, hope there's no error here: var theMenu: NSMenu? typealias FinishedDownload = (NSMenu) -> Void func loadRss(outline: Outline, subMenu: NSMenu, completed : @escaping FinishedDownload) { // Corrected name var articleList = [NSMenuItem]() let url = URL(string: outline.xmlUrl)! AF.request(url).responseRSS() { (response) -> Void in if let feed: RSSFeed = response.value { for item in feed.items { let article = NSMenuItem() let timeString = self.formatDate(item: item) if timeString != "" { var title = self.shortenText(item: item.title!) title = title + " " + timeString let someObj: NSString = item.link! as NSString article.representedObject = someObj article.action = #selector(self.openBrowser(urlSender:)) article.title = title //// Get the url from the article and add /favicon.ico to get the image //// Will add the image to each article to indicate the source let url = URL(string: outline.icon) self.getData(from: url!) { data, response, error in guard let data = data, error == nil else { return } DispatchQueue.main.async() { [weak self] in article.image = NSImage(data: data) article.image?.size = CGSize(width: 15, height: 15) } } subMenu.addItem(article) } } completed(subMenu) } } // No more return return subMenu } // Then you call as: func callIt() { theMenu = NSMenu() // Or the initial value of your submenu loadRss(outline: someOutline, subMenu: theMenu) { subMenu in theMenu = subMenu } } . You will find investing discussion here: https://stackoverflow.com/questions/36829749/how-to-wait-for-a-function-to-end-on-ios-swift-before-starting-the-second-one Note: you have probably misspelled loadRss as laodRss. Not an immediate issue, but may cause you trouble some time.
Topic: UI Frameworks SubTopic: AppKit Tags:
Nov ’21
Reply to unrecognized selector sent to instance 0x1dae7dbf8'
OOPer gave you the best advice. In addition, if you don't show code where crash occurs, pretty hard to say. You have apparently a problem with some Bool value that compares to String. You may have a look here for a similar problem, that may give you a hint. https://stackoverflow.com/questions/14662947/nscfboolean-isequaltostring-unrecognized-selector-sent-to-instance/14663108
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to How can I make this kind of scroll menu?
what about this one?  https://developer.apple.com/documentation/swiftui/picking-container-views-for-your-content No. It is for SwiftUI. And you said you use UIKit. If I have 12 items to place in this view, I need to create 12 collection views or just one with 12 elements A single collectionView of course. That's the very purpose of collectionView to provide this scrolling, selection and much more. This tutorial may help you if needed: https://www.raywenderlich.com/18895088-uicollectionview-tutorial-getting-started Just don't forget to set the width of collectionView equal (with just a few more pixels) to your cell width, in order to have only one cell horizontally and get the menu effect.
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21
Reply to How can I make this kind of scroll menu?
So do I need scrollView than if I have more items to place?  No, collectionView already manages the scrolling. You will have more items than you can display, and CollectionView will automatically take care. To create a CollectionView, just drag the object in InterfaceBuilder inside your VC. Then declare the class as the dataSource and Delegate. In code, declare that class conforms to UICollectionViewDelegate and UICollectionViewDataSource. You will be asked to provide some func to conform to protocols. Follow steps. Then create a UICollectionViewCell class (with its xib). Define all elements (image, labels) inside. Code in class would be like: class FirstCollectionViewCell: UICollectionViewCell { @IBOutlet weak var imageCell: UIImageView! @IBOutlet weak var title: UILabel! @IBOutlet weak var subTitle: UILabel! @IBOutlet weak var dateOfPublish: UILabel! // MARK: - View LifeCycle override func awakeFromNib() { super.awakeFromNib() // Initialization code } } In the class that contains the Collection, register the nib: let nib = UINib(nibName: "FirstCollectionViewCell", bundle: nil) // FirstCollectionCell is name of Nib, also name of class collectionView.register(nib, forCellWithReuseIdentifier: "FirstCollectionCell") Back to IB, in the storyboard where you have put the CollectionView, set the identifiers for the CollectionViewCell. Set the scroll direction of CollectionViewto vertical. Set the constraints so that Cell is equal width So now, start and tell if you have problems.
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21
Reply to Double initialized as Decimal returns number with trailing fractional digits
This should work: let x : Double = 0.94 print(Decimal(x)) let formatter = NumberFormatter() formatter.numberStyle = .decimal let string = formatter.string(for: x) ?? "?" print(string) giving: 0.9399999999999997952 0.94 That's for display. Of course, you should keep the raw value x if you need to reuse. Note: how is y defined in let ynumber = formatter.number(from: y) But let ynumber = formatter.number(from: string) ?? 0.0 gives: 0.9399999999999999 Because of precision of conversion.
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to Apple Safari Extension
Did you read that ? https://developer.apple.com/documentation/safariservices/safari_web_extensions/managing_safari_web_extension_permissions https://developer.apple.com/documentation/safariservices/safari_app_extensions/safari_app_extension_info_property_list_keys/adjusting_website_access_permissions
Topic: Safari & Web SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Resetting a NSPredicate
Could this help ? https://stackoverflow.com/questions/40540218/swift-3-osx-cocoa-array-controller-and-coredata-binding-search-on-multiple-colu
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Resetting a NSPredicate
So, you checked that searchFieldDidEndSearching is called ? func searchFieldDidEndSearching(_ sender: NSSearchField) {         print("V&G_Project___TrackListView searchFieldDidEndSearching : ", self)         arrayController.filterPredicate = nil     } But how could arrayController.filterPredicate be set to nil ? Is filterPredicate really an optional ? Where do you call _filterTracks ?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Open Multiple VCs from Cells in Table View
You do not yell how your cell type is defined. Is it a subclass of UITableViewCell ? Or a plain UITableViewCell ? I assume you have defined a subclass to have specific properties, as name. You could do in several ways: Create as many segues (from the VC itself) to the different destinations (route1_vc, route2_vc…) and use them: func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){ tableView.deselectRow(at: indexPath, animated: true) if let cell = tableView.cellForRow(at: indexPath) as? YourCellType { switch cell.name { case "one": performSegue(withIdentifier: "1", sender: self) case "two": performSegue(withIdentifier: "2", sender: self) default: break } } } //Here I can perform just one VC form all cells, I need each cell to open each VC (cell with name "one" opens "route1_vc"; cell with name "two" opens "route2_vc" etc.) Go directly to the VC: func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){ tableView.deselectRow(at: indexPath, animated: true) if let cell = tableView.cellForRow(at: indexPath) as? YourCellType { let storyboard = UIStoryboard(name: "Main", bundle: nil) var destViewController : UIViewController? switch cell.name { case "one": destViewController = storyboard.instantiateViewController(withIdentifier: "route1_vc") case "two": destViewController = storyboard.instantiateViewController(withIdentifier: "route2_vc") default: return } if destViewController != nil { self.present(destViewController!, animated: true, completion: nil) } } } //Here I can perform just one VC form all cells, I need each cell to open each VC (cell with name "one" opens "route1_vc"; cell with name "two" opens "route2_vc" etc.)
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Get list of SF Symbol names in code
I don't know if there is an API for this. The complete list is available on various websites, such as h t t p s : / / sfsymbols.com Or use Apple SF Symbols app to copy all of them https://stackoverflow.com/questions/63309862/way-to-easily-show-all-sf-symbols-icon-in-apps
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Get list of SF Symbol names in code
You could also see this solution (posted 3 years ago): https://developer.apple.com/forums/thread/110059
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Pass swift func result to func
Definition of API seems incorrect: Amplify.API.get(request: RESTRequest, listener:((AmplifyOperation<RESTOperationRequest, Data, APIError>.OperationResult) -> Void) There seems to be an extra ( after listener.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Pass swift func result to func
So you need to pass a closure of the same type. In the closure code, you can use your param to do what you need to do.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Memoji
I hope they will never propose such emoji which incite people to be irrespective on line.👇
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Function returns an empty array but the same function can return a filled NSMenu
Problem is that you return submenu immediately, before any item has been added: line 6 dispatches to a thread then code continues immediately at line 38, where subMenu is not yet filled 1. func laodRss(outline: Outline, subMenu: NSMenu) -> NSMenu { 2. var articleList = [NSMenuItem] () 3. 4. let url = URL(string: outline.xmlUrl)! 5. 6. AF.request(url).responseRSS() { (response) -> Void in 7. if let feed: RSSFeed = response.value { 8. for item in feed.items { 9. let article = NSMenuItem() 10. let timeString = self.formatDate(item: item) 11. if timeString != "" { 12. var title = self.shortenText(item: item.title!) 13. title = title + " " + timeString 14. 15. let someObj: NSString = item.link! as NSString 16. article.representedObject = someObj 17. article.action = #selector(self.openBrowser(urlSender:)) 18. article.title = title 19. 20. //// Get the url from the article and add /favicon.ico to get the image 21. //// Will add the image to each article to indicate the source 22. let url = URL(string: outline.icon) 23. 24. self.getData(from: url!) { data, response, error in 25. guard let data = data, error == nil else { return } 26. 27. 28. DispatchQueue.main.async() { [weak self] in 29. article.image = NSImage(data: data) 30. article.image?.size = CGSize(width: 15, height: 15) 31. } 32. } 33. subMenu.addItem(article) 34. } 35. } 36. } 37. } 38. return subMenu 39. } You have a few ways to correct this: for a very quick test, add a sleep(20) just before line 38. But that's just for test, not a solution for real app. use semaphore, to make sure all operations requests are completed use completion handler or, with iOS 15, use await/async For completion handler, should be like this (sorry, I could not test in app, hope there's no error here: var theMenu: NSMenu? typealias FinishedDownload = (NSMenu) -> Void func loadRss(outline: Outline, subMenu: NSMenu, completed : @escaping FinishedDownload) { // Corrected name var articleList = [NSMenuItem]() let url = URL(string: outline.xmlUrl)! AF.request(url).responseRSS() { (response) -> Void in if let feed: RSSFeed = response.value { for item in feed.items { let article = NSMenuItem() let timeString = self.formatDate(item: item) if timeString != "" { var title = self.shortenText(item: item.title!) title = title + " " + timeString let someObj: NSString = item.link! as NSString article.representedObject = someObj article.action = #selector(self.openBrowser(urlSender:)) article.title = title //// Get the url from the article and add /favicon.ico to get the image //// Will add the image to each article to indicate the source let url = URL(string: outline.icon) self.getData(from: url!) { data, response, error in guard let data = data, error == nil else { return } DispatchQueue.main.async() { [weak self] in article.image = NSImage(data: data) article.image?.size = CGSize(width: 15, height: 15) } } subMenu.addItem(article) } } completed(subMenu) } } // No more return return subMenu } // Then you call as: func callIt() { theMenu = NSMenu() // Or the initial value of your submenu loadRss(outline: someOutline, subMenu: theMenu) { subMenu in theMenu = subMenu } } . You will find investing discussion here: https://stackoverflow.com/questions/36829749/how-to-wait-for-a-function-to-end-on-ios-swift-before-starting-the-second-one Note: you have probably misspelled loadRss as laodRss. Not an immediate issue, but may cause you trouble some time.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to How can I make this kind of scroll menu?
You call it a menu, but that's not a menu in fact. It is simply (at first glance) a collection View. If you know how to create a collection view, that is very easy to do, with a custom cell that contains an image and a few labels below.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to unrecognized selector sent to instance 0x1dae7dbf8'
OOPer gave you the best advice. In addition, if you don't show code where crash occurs, pretty hard to say. You have apparently a problem with some Bool value that compares to String. You may have a look here for a similar problem, that may give you a hint. https://stackoverflow.com/questions/14662947/nscfboolean-isequaltostring-unrecognized-selector-sent-to-instance/14663108
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to How can I make this kind of scroll menu?
what about this one?  https://developer.apple.com/documentation/swiftui/picking-container-views-for-your-content No. It is for SwiftUI. And you said you use UIKit. If I have 12 items to place in this view, I need to create 12 collection views or just one with 12 elements A single collectionView of course. That's the very purpose of collectionView to provide this scrolling, selection and much more. This tutorial may help you if needed: https://www.raywenderlich.com/18895088-uicollectionview-tutorial-getting-started Just don't forget to set the width of collectionView equal (with just a few more pixels) to your cell width, in order to have only one cell horizontally and get the menu effect.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to How can I make this kind of scroll menu?
So do I need scrollView than if I have more items to place?  No, collectionView already manages the scrolling. You will have more items than you can display, and CollectionView will automatically take care. To create a CollectionView, just drag the object in InterfaceBuilder inside your VC. Then declare the class as the dataSource and Delegate. In code, declare that class conforms to UICollectionViewDelegate and UICollectionViewDataSource. You will be asked to provide some func to conform to protocols. Follow steps. Then create a UICollectionViewCell class (with its xib). Define all elements (image, labels) inside. Code in class would be like: class FirstCollectionViewCell: UICollectionViewCell { @IBOutlet weak var imageCell: UIImageView! @IBOutlet weak var title: UILabel! @IBOutlet weak var subTitle: UILabel! @IBOutlet weak var dateOfPublish: UILabel! // MARK: - View LifeCycle override func awakeFromNib() { super.awakeFromNib() // Initialization code } } In the class that contains the Collection, register the nib: let nib = UINib(nibName: "FirstCollectionViewCell", bundle: nil) // FirstCollectionCell is name of Nib, also name of class collectionView.register(nib, forCellWithReuseIdentifier: "FirstCollectionCell") Back to IB, in the storyboard where you have put the CollectionView, set the identifiers for the CollectionViewCell. Set the scroll direction of CollectionViewto vertical. Set the constraints so that Cell is equal width So now, start and tell if you have problems.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Double initialized as Decimal returns number with trailing fractional digits
This should work: let x : Double = 0.94 print(Decimal(x)) let formatter = NumberFormatter() formatter.numberStyle = .decimal let string = formatter.string(for: x) ?? "?" print(string) giving: 0.9399999999999997952 0.94 That's for display. Of course, you should keep the raw value x if you need to reuse. Note: how is y defined in let ynumber = formatter.number(from: y) But let ynumber = formatter.number(from: string) ?? 0.0 gives: 0.9399999999999999 Because of precision of conversion.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21