Use https to access courses.json

Since OS X 10.11+ enforces the use of secure connection with App Transport Security accessing the json file using a http url will fail.

One could add an exception to the applications info.plist file, but as bignerdranch luckily has an SSL certificate it would be best to change the url to https://… in your code.

It’s me again. Sorry this post will be a little long with the code included.

I can access the BNR data using Safari with: and all the data shows up.

Trying through the RanchForecast app I was getting the App Transport security warning. I tried the above suggestion, which I know was from 2015 and things change, but that didn’t work. It also doesn’t work using https:// in Safari.

I researched online and found what would need to be added to the info.plist file to allow an exception. I added the following code to the info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "    1.0.dtd">
<plist version="1.0">
<string>Copyright © 2018 JETApps. All rights reserved.</string>
 				 <!--Include to allow subdomains-->
 				 <!--Include to allow HTTP requests-->
 				 <!--Include to specify minimum TLS version-->

The portion I added starts with “NSAppTransportSecurity” and that allowed me to get past the security warning.

Now, however, when I run the app I get this warning after it tries to connect a few times:

“A server with the specified hostname could not be found.”

I am using the recommend “” that works in Safari.

Here is my MainWindowController.swift:

import Cocoa

class MainWindowController: NSWindowController {

let fetcher = ScheduleFetcher()
@objc dynamic var courses: [Course] = []

override var windowNibName: NSNib.Name? {
	return NSNib.Name(rawValue: "MainWindowController")

override func windowDidLoad() {
	fetcher.fetchCoursesUsing { (result) in
		switch result {
		case .Success(let courses):
			print("Got courses: \(courses)") = courses
		case .Failure(let error):
			print("Got error: \(error)")
			NSAlert(error: error).runModal() = []


and here is my ScheduleFetcher.swift:

import Foundation

class ScheduleFetcher {

enum FetchCoursesResult {
	case Success([Course])
	case Failure(NSError)

let session: URLSession

init() {
	let config = URLSessionConfiguration.default
	session = URLSession(configuration: config)


func fetchCoursesUsing(completionHandler: @escaping(FetchCoursesResult) -> (Void)) {
	let url = NSURL(string: "")!
	let request = URLRequest(url: url as URL)
	let task = session.dataTask(with: request, completionHandler: {
		(data, response, error) -> Void in
		var result: FetchCoursesResult
		if data == nil {
			result = .Failure(error! as NSError)
		} else {
			print("Received \(String(describing: data?.count)) bytes.")
			result = .Success([])	// Empty array until parsing is added

Any ideas? I know I must be missing something again…

Once again, all I have to do is post the problem on here and I find the solution shortly after. I had to activate Outgoing Connections in the sandbox! Duh.

it now connects and downloads the data. Onward!

it doesn’t work. Is the URL out of date?

When I run my app I got a alert saying “A server with the specified hostname could not be found.”

Need some help? Is the server still alive?

The URL is no longer valid - tried both and in Postman and both resulted in “Could not get any response.” Is there a replacement URL that will provide the data?