Post

Replies

Boosts

Views

Activity

MKMarkerAnnotationView glyphImage for a cluster annotation
Hi, I want to set the glyphImage property for an annotation view (MKMarkerAnnotationView) of a cluster annotation (MKClusterAnnotation). Using the below code, inside the marker I get, instead of the glyphImage, the standard cluster number. func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { if let cluster = annotation as? MKClusterAnnotation { var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "GroupMapClusterAnnotation") if annotationView == nil { annotationView = MKMarkerAnnotationView(annotation: cluster, reuseIdentifier: "GroupMapClusterAnnotation") } (annotationView as? MKMarkerAnnotationView)?.glyphImage = UIImage(systemName: "star.fill") return annotationView } } I think that the problem is that if you keep the glyphText property empty, MapKit automatically set it with the number of the cluster member annotations. The documentation for glyphImage says: Use this property or the glyphText property to specify the marker balloon content. If you specify both an image and text, MapKit displays the text. So, MapKit is setting glyphText with a value an therefore the glyphImage property is ignored. How can we use the glyphImage property for a cluster annotation? Thank you
1
0
1.5k
Jun ’22
MKErrorDomain 4 when performing a MKLocalSearch with an MKLocalSearchCompletion
Hi, I have a controller where the user can search for map locations or points of interest by typing inside a search box. To retrieve the list of results I set the queryFragment parameter of a MKLocalSearchCompleter with the search content. This correctly gives me back a list of MKLocalSearchCompletion of locations and points of interest. When a user tap on one of this locations, I need to load the coordinates. In order to do that I do a MKLocalSearch passing the selected MKLocalSearchCompletion, like so: let item = items[indexPath.row] let request = MKLocalSearch.Request(completion: item) let search = MKLocalSearch(request: request) search.start { (response, error) in //Do stuff with the result. //For some specific items I receive an MKErrorDomain 4 error. } This works most of the time, but for some specific items the MKLocalSearch call return the error: Error Domain=MKErrorDomain Code=4 "(null)" UserInfo={MKErrorGEOError=-8} This error correspond to "placemarkNotFound", ie MapKit is not able to find a placemark for the specific MKLocalSearchCompletion. I just don't understant why this should be the case. The MKLocalSearchCompletion is returned by MapKit. If it is returned by MapKit then a corresponding placemark should exist, right? Why then is MapKit unable to perform a local search on it? The problem now is that I present the user with a list of completions returned by MapKit but tapping some of them nothing happens because I cannot determine their respective coordinates. Why is the search failing sometime? I miss something? Thank you
1
0
1.9k
Jun ’22
iOS 16 UITextView line spacing when empty
Hi, I just discovered a weird bug with UITextView on iOS 16 beta 4. For some reason now, when the scrolling is disabled, the intrinsic content size of the text view is considering the line spacing even when the textview is empty. For example, in the below code we are setting a big lineSpacing of 50 to the text view typingAttributes attribute. class ViewController: UIViewController { @IBOutlet weak var textView: UITextView! { didSet { //Let's set the textView typingAttributes with a lineSpacing of 50. var attributes = [NSAttributedString.Key: Any]() let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle() paragraphStyle.lineSpacing = 50 attributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle attributes[NSAttributedString.Key.font] = UIFont.preferredFont(forTextStyle: .body) textView.typingAttributes = attributes } } } On previous iOS versions, everyting it's ok and the line spacing is added only when there are more than one line (see below image). However, on iOS 16 beta 4, the line spacing is added also when the content is empty (see below image on the left). A soon as we type something the height collapse to the correct height (see below image in the center). Is this a new expected behavior or a bug? If it is a bug, someone has found a temporary fix for that? Thank you
1
1
4.3k
Sep ’22
Loop through CoreData objects and memory issue
I have an entity named Image with a binary attribute named imageData. I need to cycle trough all Image objects and do something with the data contained inside the imageData attribute. This is the code: for image in managedObjectContext.allImages { autoreleasepool { var imageData = image.imageData } } I have a lot of objects and every imageData has something like 500KB of data for a total of 3GB of data. The problem is that each time the imageData attribute is used, the data go into memory and not released until the loop is done. This is causing the memory to grow up to 3GB crashing the app. I also tried to turn the object into a fault when I'm done with it by calling refresh(_:mergeChanges:) but nothing changes: for image in managedObjectContext.allImages { autoreleasepool { var imageData = image.imageData managedObjectContext.refresh(image, mergeChanges: false) } } How can I cycle trough all objects without filling up all the memory? Thank you
1
0
1.3k
Apr ’23
Search bar in navigation bar displayed as icon
Hi, I have a controlled contained in a split view controller primary controller with a UISearchController assigned in navigationItem.searchController. On iPhone the search bar is directly displayed in the navigation bar. This is want I want. But on iPad, the search bar is hidden and a search button is displayed in the top right of the navigation bar. In order to display the search bar the user must click on the icon to display the search bar. I want the search bar to always be visible, like on iPhone. How can I achieve that? This is the code I use to include the UISearchController: let searchController = UISearchController(searchResultsController: nil) searchController.searchResultsUpdater = self searchController.obscuresBackgroundDuringPresentation = false searchController.hidesNavigationBarDuringPresentation = false navigationItem.searchController = searchController navigationItem.hidesSearchBarWhenScrolling = false And this is the result on both devices: Thank you
1
0
2.0k
Aug ’23
String(localized:) return \' as thousands separator
Just found something weird with the String(localized:) method. Let's say that I have a "%lld apples" sentence inside a string catalog. If I call String(localized:"\(1000) apples") when on the device settings the number format is "1'234'567.89" and the device language is English, then the following string is returned: 1\'000 apples Any idea why the ' character has a backslash? It's a bug or I miss something? Thank you
1
0
821
Nov ’23
StoreKit 2 Transaction.currentEntitlements questions
Hi, I'm starting using StoreKit 2 and I have some questions regarding transactions. To check which non-consumable in-app purchases the user has purchased, immediately after starting the app I look at Transaction.currentEntitlements. That's working fine, but I have some questions about it. Question 1: What happens if the user is not connected to the internet? Will Transaction.currentEntitlements still return data? Question 2: What happens if the user sign out from the AppStore? Will Transaction.currentEntitlements be empty? Question 3: What happens if the user sign in AppStore with different credentials? Transaction.currentEntitlements will return the transaction of the new AppStore user? Thank you
0
3
873
May ’22
Mac Catalyst UIButton configuration when window is not active
Hi, I'm trying to define the style of an UIButton using UIButton.Configuration in a Mac Catalyst app. I was able to configure the component as I want except one thing. I want to change the style of the button when the window is not active. The default filled style automatically do this. For example below you can see a button configured with UIButton.Configuration.filled(). If the window become inactive (for example by activating another application) the color of the button change, like so: Now, If I configure a button with this configuration: var configuration = UIButton.Configuration.plain() configuration.background.strokeColor = .gray configuration.baseForegroundColor = .red configuration.baseBackgroundColor = .clear the button display with this configuration when the window is active: but also when it's not active: I want to change the text color from red to gray when the window is not active. Someone know how to do it? Thank you
0
0
1.2k
May ’22
Files with "interim" extension inside _EXTERNAL_DATA
In a Core Data store I have a binary data attribute with “Allows External Storage” set to true. Everything work as expected, i.e. the data of this attribute is saved inside the _EXTERNAL_DATA folder. For every data stored into that attribute, a file is created inside _EXTERNAL_DATA with a UUID as file name and without extension. That's expected. For some reason the _EXTERNAL_DATA folder of a particular user was full of files with an “.interim” extension. Somebody know what are this files? In which cases files are saved with the ".interim" extension? Do we need to do anything with these files? Can they be deleted? Thank you
0
0
835
Mar ’23
Localizer hint for object attributes
When using storyboards, string catalogs automatically grab translation comments from the "Localizer Hint" attribute of the objects in the storyboard. The problem is that we can only specify a single comment per object. What if we need to specify a specific comment for some of the attributes of the object? For example, I often need to provide a specific comment to each segment title of segmented control objects. Currently, I'm doing that by setting the managed property of each string to "Manual" and setting the comment directly from the string catalog. There is a better way to handle these cases?
0
0
582
Oct ’23
StoreKit 2: Transaction.updates don't emits refunds at app launch
If an in-app purchase is made when my app is not running, the next time the app launches Transaction.updates will emits a transaction for the purchase. That's great. But if an in-app purchase is refunded when my app is not running, the next time the app launches Transaction.updates will NOT emits a transaction for the refund. Is that the expected behaviour? If yes, in order to check for refunds at app launch, are we supposed to cycle trough Transaction.all and search for them? Thank you
0
0
694
May ’24