Silver Challenge - Performances

#1

Hi Everyone,

I’m wondering if its normal to get 202Memory when the app is running and 19% when i activate the “cycle run” on IOS simulator?
My code looks like this:

import UIKit
import MapKit

class MapViewController: UIViewController, MKMapViewDelegate {

var mapView: MKMapView!

override func loadView() {
    // Create a new map
    mapView = MKMapView()
    
    // Set it as "the" view of this controller
    view = mapView
    mapView.delegate = self
    mapView.showsUserLocation = true
    mapView.scrollEnabled = false
    
    let segmentedControl = UISegmentedControl(items: ["Standard", "Hybrid", "Satellite"])
    segmentedControl.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.5)
    segmentedControl.selectedSegmentIndex = 0
    segmentedControl.addTarget(self, action: #selector(mapTypeChanged(_:)), forControlEvents: .ValueChanged)
    segmentedControl.translatesAutoresizingMaskIntoConstraints = false
    
    view.addSubview(segmentedControl)
    
    let topConstraint = segmentedControl.topAnchor.constraintEqualToAnchor(topLayoutGuide.bottomAnchor, constant: 8)
    
    let margins = view.layoutMarginsGuide
    let leadingConstraint = segmentedControl.leadingAnchor.constraintEqualToAnchor(margins.leadingAnchor)
    let trailingConstraint = segmentedControl.trailingAnchor.constraintEqualToAnchor(margins.trailingAnchor)
    
    topConstraint.active = true
    leadingConstraint.active = true
    trailingConstraint.active = true
}

func mapTypeChanged(segControl: UISegmentedControl) {
    switch segControl.selectedSegmentIndex {
    case 0:
        mapView.mapType = .Standard
    case 1:
        mapView.mapType = .Hybrid
    case 2:
        mapView.mapType = .Satellite
    default:
        break
    }
}

func mapView(_mapView: MKMapView, didUpdateUserLocation userLocation: MKUserLocation) {
    print("mapView delegate !")
    if let coord = userLocation.location?.coordinate {
        let region = MKCoordinateRegionMakeWithDistance(coord, 200, 200)
        mapView.setRegion(region, animated: true)
    }
}

// Done once during the run of the app
override func viewDidLoad() {
    super.viewDidLoad()
    print("MapViewController loaded its view")
}

// Done each time the view controllers appears
override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    print("MapViewController will appear")
}    
}

May I do something’s wrong ?

#2

I looked through all the Simulator menus, and I can’t find “cycle run”. I searched under the Simulator’s Help and nothing was found for “cycle run”. Finally, I searched google, and I found nothing. What is “the cycle run”?

#3

Hi,

This option is located on Debug menu (when you run iphone simulator) as you could see on the screenshoot

#4

“City Run” != “cycle run”

In any case, if I click on my Current Location button,which zooms in on a portion of the map, then select Debug> City Run, the beacon on my map moves to the Palo Alto/San Jose area, and the function:

func mapView(mapView: MKMapView, didUpdateUserLocation userLocation: MKUserLocation)

is repeatedly called over and over.

What is the 202Memory and 19% that you refer to?

#5

oops sorry i think i wrote the post to quickly.
When you run the app, on xdebug you have access to this panel

Just wondering if cpu and memory used are “normal” on this case ? or if there is a way to reduce it ?

#6

When I look at Debug Navigator, I see CPU = 78% and Memory = 240MB