Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Weather App Fetching Data From the Web Making a Simple Network Request

Jack Blankenship
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jack Blankenship
Full Stack JavaScript Techdegree Graduate 39,036 Points

Network request is causing soft crash.

I've gone through the rest of this hoping the error would resolve later in the class. However, I am still getting the following when making the network request. It is also double calling DarkSky. Not sure if this is a version problem with Xcode or I missed a step somewhere. Xcode version is 8.2.1 running on an iMac OSx 10.11.6

2017-08-04 10:10:01.942216 Stormy[6193:422492] [] nw_host_stats_add_src recv too small, received 24, expected 28
2017-08-04 10:10:01.946311 Stormy[6193:422492] [] nw_host_stats_add_src recv too small, received 24, expected 28
2017-08-04 10:10:01.947558 Stormy[6193:422492] [] nw_host_stats_add_src recv too small, received 24, expected 28
2017-08-04 10:10:01.948540 Stormy[6193:422492] [] nw_host_stats_add_src recv too small, received 24, expected 28
2017-08-04 10:10:01.949717 Stormy[6193:422492] [] nw_host_stats_add_src recv too small, received 24, expected 28
2017-08-04 10:10:01.951064 Stormy[6193:422492] [] nw_host_stats_add_src recv too small, received 24, expected 28
2017-08-04 10:10:01.953505 Stormy[6193:422492] [] nw_host_stats_add_src recv too small, received 24, expected 28
2017-08-04 10:10:01.955481 Stormy[6193:422492] [] nw_host_stats_add_src recv too small, received 24, expected 28
2017-08-04 10:10:01.961249 Stormy[6193:422471] [] nw_host_stats_add_src recv too small, received 24, expected 28
2017-08-04 10:10:02.001618 Stormy[6193:422471] [] ____nwlog_simulate_crash_inner_block_invoke dlopen CrashReporterSupport failed
2017-08-04 10:10:02.019715 Stormy[6193:422471] [] __nwlog_err_simulate_crash simulate crash failed "nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available"
2017-08-04 10:10:02.021062 Stormy[6193:422471] [] nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available, dumping backtrace:
        [x86_64] libnetcore-856.30.16
    0   libsystem_network.dylib             0x000000010f55a666 __nw_create_backtrace_string + 123
    1   libnetwork.dylib                    0x000000010f838006 nw_socket_add_input_handler + 3164
    2   libnetwork.dylib                    0x000000010f815555 nw_endpoint_flow_attach_protocols + 3768
    3   libnetwork.dylib                    0x000000010f814572 nw_endpoint_flow_setup_socket + 563
    4   libnetwork.dylib                    0x000000010f813298 -[NWConcrete_nw_endpoint_flow startWithHandler:] + 2612
    5   libnetwork.dylib                    0x000000010f82eae1 nw_endpoint_handler_path_change + 1261
    6   libnetwork.dylib                    0x000000010f82e510 nw_endpoint_handler_start + 570
    7   libnetwork.dylib                    0x000000010f8461f9 nw_endpoint_resolver_start_next_child + 2240
    8   libdispatch.dylib                   0x000000010f2d7978 _dispatch_call_block_and_release + 12
    9   libdispatch.dylib                   0x000000010f3010cd _dispatch_client_callout + 8
    10  libdispatch.dylib                   0x000000010f2dee17 _dispatch_queue_serial_drain + 236
    11  libdispatch.dylib                   0x000000010f2dfb4b _dispatch_queue_invoke + 1073
    12  libdispatch.dylib                   0x000000010f2e2385 _dispatch_root_queue_drain + 720
    13  libdispatch.dylib                   0x000000010f2e2059 _dispatch_worker_thread3 + 123
    14  libsystem_pthread.dylib             0x000000010f6aa4de _pthread_wqthread + 1129
    15  libsystem_pthread.dylib             0x000000010f6a8341 start_wqthread + 13
Optional(28210 bytes)

current code is below

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let currentWeather = CurrentWeather(temperature: 85.0, humidity: 0.7512, precipitationProbability: 0.1425, summary: "Hot!", icon: "clear-day")
        let currentWeatherViewModel = CurrentWeatherViewModel(model: currentWeather)

        displayWeather(using: currentWeatherViewModel)

        let base = URL(string: "https://api.darksky.net/forecast/\(darkSkyApiKey)/")
        guard let forecastUrl = URL(string: "37.8267,-122.4233", relativeTo: base)
            else { return }

        let configuration = URLSessionConfiguration.default
        let session = URLSession(configuration: configuration)
        let request = URLRequest(url: forecastUrl)
        let dataTask = session.dataTask(with: request) {data, response, error in
            print(data)
        }

        dataTask.resume()
    }

2 Answers

Chris Stromberg
PLUS
Chris Stromberg
Courses Plus Student 13,389 Points

Is your app able to run or is it crashing? Also are you using a personal API key or the one that Pasan created?

There has been a lot of discussion about excessive and unhelpful Xcode 8 logging being displayed when running apps in the simulator. I have updated my mac to macOSsierra 10.12.6 and I am running Xcode 8.3.3 and have not seen any of the excessive logging occurring in the debug area.

Jack Blankenship
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jack Blankenship
Full Stack JavaScript Techdegree Graduate 39,036 Points

The app runs, but does all that logging. I am using my own key from when I did this project under Swift 2.0. I will see if upgrading to the latest Xcode stops that.

At least the double call to DarkSky has stopped.

Chris Stromberg
Chris Stromberg
Courses Plus Student 13,389 Points

Prior to the update I did see a lot of this logging. It looks like some of this may have been fixed with the recent updates.