Post

Replies

Boosts

Views

Activity

Reply to Directions to annotation from current location in MapKit
I would like to do this like here: https://www.raywenderlich.com/7738344-mapkit-tutorial-getting-started If you want to do things as shown in the tutorial, you need to instantiate a MKMapItem as instructed. As you are using MKPointAnnotation, you can define an extension like this: extension MKPointAnnotation { var mapItem: MKMapItem { let placemark = MKPlacemark(coordinate: self.coordinate) return MKMapItem(placemark: placemark) } } To utilized this extension, you may need to pass the right annotation (which needs to be an MKPointAnnotation) to didClickDetailDisclosureNavigation(button:). Which may be hard using a usual UIButton. You should better define your own button type which can hold an annotation. Not too complex: class AnnotationButton: UIButton { var annotation: MKPointAnnotation? } (Please do not put the extension and the class definition inside some other type. They need to be toplevel definitions.) Your code would become something like this: func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { guard !(annotation is MKUserLocation) else { return nil } //mapView.delegate = self //->Move this to `viewDidLoad()` //This `annotationView` will be shadowed by the following `annotationView`, not used. //let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: String(annotation.hash)) let identifier = "identifier" //annotationView.canShowCallout = true guard let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier, for: annotation) as? MKMarkerAnnotationView else { return nil } //... let leftButton = AnnotationButton(frame: CGRect( //<- origin: .zero, size: CGSize(width: 25, height: 25))) leftButton.setBackgroundImage(#imageLiteral(resourceName: "nav"), for: .normal) annotationView.leftCalloutAccessoryView = leftButton leftButton.addTarget(self, action: #selector(didClickDetailDisclosureNavigation(button:)), for: .touchUpInside) //↓↓ if let pointAnnotation = annotation as? MKPointAnnotation { leftButton.annotation = pointAnnotation } //... return annotationView } @objc func didClickDetailDisclosureNavigation(button: AnnotationButton) { //<- let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving] //↓↓ if let mapItem = button.annotation?.mapItem { mapItem.openInMaps(launchOptions: launchOptions) } } I haven't tried it myself (as you are not showing many parts of your code), but please try.
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’21
Reply to UILabel with superscript text
Several ways. Some examples: //Using attributed string let baseString = NSAttributedString(string: "1:47", attributes: [ .font: UIFont.systemFont(ofSize: 48), ]) let pmString = NSAttributedString(string: "PM", attributes: [ .baselineOffset: 16, .font: UIFont.systemFont(ofSize: 28), ]) let attributedString = NSMutableAttributedString() attributedString.append(baseString) attributedString.append(pmString) label1.attributedText = attributedString label1.backgroundColor = .black label1.textColor = .white //Using Unicode characters //let text = "1:47\u{1D3E}\u{1D39}" let text = "1:47\u{1D2C}\u{1D39}" label2.text = text label2.backgroundColor = .black label2.textColor = .white If you can find a better font (which may not be included in standard iOS devices), the result may get better:
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’21
Reply to SwiftUI Table does not work when trying to use Int values
I tried your code with Xcode 3.1 and got the following error: (I needed to fill many parts missing in your shown code, so some other parts still hidden may be affecting.) The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions The error is far from kind enough for fixing the issue, but it may very often caused by some obvious syntax errors in a ViewBuilder. As far as I check the code, this line is obviously odd: TableColumn("disc", Int: \.discNumber) TableColumn does not have an initializer init(_:Int:). And any initializers of TableColumn taking a KeyPath to Int requires RowValue as NSObject. So, a simple workaround may be defining an extension which return String. extension AlbumTracks { var discNumberString: String { String(discNumber) } } And use it as follows: TableColumn("disc", value: \.discNumberString) But as already noted, other parts may be affecting. If this workaround does not work, you may need to show more info.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’21
Reply to Axie infinity
Contact to the author of the app directly. The developer site is not a place to request joining to TestFlight.
Oct ’21