This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestGist { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FeedItem { | |
let title: String | |
let thumbnailURL: URL | |
} | |
let items = [FeedItem(title: "title", thumbnailURL: URL(string: "http:a-url.com")!), | |
FeedItem(title: "another title", thumbnailURL: URL(string: "http:b-url.com")!), | |
FeedItem(title: "even another title", thumbnailURL: URL(string: "http:c-url.com")!), | |
FeedItem(title: "even another another title", thumbnailURL: URL(string: "http:d-url.com")!)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var urls = [URL]() | |
for item in items { | |
urls.append(item.thumbnailURL) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let urls = items.map{$0.thumbnailURL} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let urls = items.map { (item) -> URL in | |
return item.thumbnailURL | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FeedItem { | |
let title: String | |
let thumbnailURL: URL? | |
} | |
let items = [FeedItem(title: "title", thumbnailURL: nil), | |
FeedItem(title: "another title", thumbnailURL: URL(string: "http:b-url.com")!), | |
FeedItem(title: "even another title", thumbnailURL: URL(string: "http:c-url.com")!), | |
FeedItem(title: "even another another title", thumbnailURL: URL(string: "http:d-url.com")!)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var urls = [URL]() | |
for item in items { | |
if let url = item.thumbnailURL { | |
urls.append(url) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let urls = items.compactMap { (item) -> URL? in | |
return item.thumbnailURL | |
} | |
// result: [http:b-url.com, http:c-url.com, http:d-url.com] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let urls = items.compactMap { $0.thumbnailURL } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FeedItem { | |
let title: String | |
let thumbnailURL: URL? | |
let isFavorite: Bool | |
} | |
let items = [FeedItem(title: "title", thumbnailURL: nil, isFavorite: false), | |
FeedItem(title: "another title", thumbnailURL: URL(string: "http:b-url.com")!, isFavorite: false), | |
FeedItem(title: "even another title", thumbnailURL: URL(string: "http:c-url.com")!, isFavorite: true), | |
FeedItem(title: "even another another title", thumbnailURL: URL(string: "http:d-url.com")!, isFavorite: true)] |
OlderNewer