# Introduction | raywenderlich.com

**URL:** <https://forums.kodeco.com/t/introduction-raywenderlich-com/112657>\
**Category:** 🎓 Courses & Articles\
**Created:** [June 19, 2020, 8:02pm UTC](https://forums.kodeco.com/t/introduction-raywenderlich-com/112657 "2020-06-19T20:02:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdmoakley](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bdmoakley/32/108772_2.png) [@bdmoakley](https://forums.kodeco.com/u/bdmoakley)\
**Post date:** [June 19, 2020, 8:02pm UTC](https://forums.kodeco.com/t/introduction-raywenderlich-com/112657/1 "2020-06-19T20:02:37Z")

</div>

* * *
This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/10376245-networking-with-urlsession/lessons/33](https://www.raywenderlich.com/10376245-networking-with-urlsession/lessons/33)

---

<div class="post-metadata">

**Author:** ![fweissi](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/fweissi/32/104356_2.png) [@fweissi](https://forums.kodeco.com/u/fweissi)\
**Post date:** [June 26, 2020, 2:47am UTC](https://forums.kodeco.com/t/introduction-raywenderlich-com/112657/2 "2020-06-26T02:47:08Z")

</div>

Awesome examples using combine. I did not know that I could use compactMap the way you demonstrated. I also liked how you used Publishers.zip and flapMap. When I have used zip in the past, I would use something this this example.

let pubisher1 = URLSession…  
let publisher2 = URLSession…

Then I would write: publisher1.zip(publisher1)…

Publishers.zip(publisher1, publisher2) just reads better.

Instead of flatMap, I had been using tryMap and adding the secondary call in there. I am so excited to see other examples of Combine methodologies to enhance my understanding to make better use of the Library.

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [July 8, 2020, 5:57am UTC](https://forums.kodeco.com/t/introduction-raywenderlich-com/112657/3 "2020-07-08T05:57:17Z")

</div>

@fweissi Really glad you like it! Cheers! :]

---

<div class="post-metadata">

**Author:** ![malauch](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/malauch/32/84760_2.png) [@malauch](https://forums.kodeco.com/u/malauch)\
**Post date:** [July 29, 2020, 4:59am UTC](https://forums.kodeco.com/t/introduction-raywenderlich-com/112657/4 "2020-07-29T04:59:38Z")

</div>

Hi,  
I just watched this lesson and have a question. At the begging of the video you said that authorization challenges are resolved in `URLSessionDelegate` in appropriate methods. However in the example you just manually inject authorization HTTP header value into the URLRequest. What is the reason for that? Additionally “authorization” header is listed by Apple as _Reserved HTTP Header_ which shouldn’t be manually modified. So basically your example is against Apple’s recommendations.

---

<div class="post-metadata">

**Author:** ![pkprasad](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/pkprasad/32/81494_2.png) [@pkprasad](https://forums.kodeco.com/u/pkprasad)\
**Post date:** [August 10, 2020, 9:22pm UTC](https://forums.kodeco.com/t/introduction-raywenderlich-com/112657/5 "2020-08-10T21:22:15Z")

</div>

The tutorials are well paced and detailed with good amount of code to practice on. I tried to modify one of example on authentication into code using Combine but am getting the error “Generic parameter T could not be inferred”.

Basically I am trying to use auth token output of one publisher and create another publisher to give out URLRequest like this:

let acronymrequestpublisher = tokenpublisher  
.map { token in  
var urlrequest = URLRequest(url:acronymurl)  
return urlrequest  
}

But this is giving the generic parameter T could not be found error. I do not see any error if I simply return created URLRequest in same line like this:  
let acronymrequestpublisher = tokenpublisher  
.map { token in  
return URLRequest(url:acronymurl)  
}

Any reason why Swift compiler is not able to infer T in first place?

---

<div class="post-metadata">

**Author:** ![bdmoakley](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bdmoakley/32/108772_2.png) [@bdmoakley](https://forums.kodeco.com/u/bdmoakley)\
**Post date:** [August 10, 2020, 10:00pm UTC](https://forums.kodeco.com/t/introduction-raywenderlich-com/112657/6 "2020-08-10T22:00:09Z")

</div>

Hey there,

If the Swift compiler is having issues with inferring the type, you can help it out by specifying the return value. Try this instead:

```
let acronymrequestpublisher = tokenpublisher
.map { token -> URLRequest in
  return URLRequest(url:acronymurl)
}

```

I hope that helps!

---

<div class="post-metadata">

**Author:** ![pkprasad](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/pkprasad/32/81494_2.png) [@pkprasad](https://forums.kodeco.com/u/pkprasad)\
**Post date:** [August 10, 2020, 10:22pm UTC](https://forums.kodeco.com/t/introduction-raywenderlich-com/112657/7 "2020-08-10T22:22:01Z")

</div>

Thanks, that helped.

---

<div class="post-metadata">

**Author:** ![pkprasad](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/pkprasad/32/81494_2.png) [@pkprasad](https://forums.kodeco.com/u/pkprasad)\
**Post date:** [August 10, 2020, 10:25pm UTC](https://forums.kodeco.com/t/introduction-raywenderlich-com/112657/8 "2020-08-10T22:25:15Z")

</div>

I am able to successfully re-create the authentication example code using Combine. Pasting part of code below for others:

guard let loginurl = loginEndpoint else {  
fatalError()  
}

guard let acronymurl = newEndpoint else {  
fatalError()  
}

let loginstring = “(user.email):(user.password)”  
guard let logindata = loginstring.data(using: .utf8) else {  
fatalError()  
}

let encodedstring = logindata.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: 0))  
var urlrequest = URLRequest(url: loginurl)  
urlrequest.httpMethod = “POST”  
urlrequest.allHTTPHeaderFields = [  
“accept”:“application/json”,  
“content-type”:“application/json”,  
“authorization”:“Basic (encodedstring)”  
]

//Create first publisher that requests token  
let tokenpublisher = session.dataTaskPublisher(for: urlrequest)  
.map(.data)  
.decode(type: Auth.self, decoder: JSONDecoder())  
.map(.token)  
.mapError {  
$0 as Error  
}

//Create subsequent publisher that uses the token from tokenpublisher, create request to create new acronym  
let acronym = Acronym(short: “PBS”, long: “Peanut Butter and Sandwich”)  
let acronymrequestpublisher = tokenpublisher  
.compactMap {urlRequestWithToken(token:$0, acronym:acronym)}  
.flatMap { request in  
session.dataTaskPublisher(for: request)  
.mapError {$0 as Error }  
}

var cancellables:Set = []

Publishers.Zip(tokenpublisher,acronymrequestpublisher)  
.receive(on: DispatchQueue.main)  
.sink(receiveCompletion: { completion in  
print(completion)  
}) { token, response in  
print(String(data: response.data, encoding: .ascii) )  
}  
.store(in: &cancellables)

func urlRequestWithToken(token:String, acronym:Acronym)-\>URLRequest? {  
guard let acronymdata = try? encoder.encode(acronym) else {  
return nil  
}  
guard let url = newEndpoint else {  
return nil  
}  
var urlrequest = URLRequest(url: url)  
urlrequest.httpMethod = “POST”  
urlrequest.allHTTPHeaderFields = [  
“accept”:“application/json”,  
“content-type”:“application/json”,  
“authorization”:“Bearer (token)”  
]  
urlrequest.httpBody = acronymdata  
return urlrequest  
}

---

<div class="post-metadata">

**Author:** ![bdmoakley](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bdmoakley/32/108772_2.png) [@bdmoakley](https://forums.kodeco.com/u/bdmoakley)\
**Post date:** [August 10, 2020, 10:28pm UTC](https://forums.kodeco.com/t/introduction-raywenderlich-com/112657/9 "2020-08-10T22:28:52Z")

</div>

Awesome work there! Well done!

---

<div class="post-metadata">

**Author:** ![punkhornsw](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/punkhornsw/32/102910_2.png) [@punkhornsw](https://forums.kodeco.com/u/punkhornsw)\
**Post date:** [February 4, 2021, 6:41pm UTC](https://forums.kodeco.com/t/introduction-raywenderlich-com/112657/10 "2021-02-04T18:41:22Z")

</div>

Hey what is the url to get a listing of entries in the app?

---

<div class="post-metadata">

**Author:** ![txpilot03](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/txpilot03/32/102075_2.png) [@txpilot03](https://forums.kodeco.com/u/txpilot03)\
**Post date:** [February 11, 2021, 6:22am UTC](https://forums.kodeco.com/t/introduction-raywenderlich-com/112657/11 "2021-02-11T06:22:10Z")

</div>

Im getting the same issue, the url address comes back with a status code of 200 but it looks like there is nothing there at that address anymore. When navigating to the url in Safari nothing is there. Any suggestions??
