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
CREATE TABLE "Album" | |
( | |
"AlbumId" INT NOT NULL, | |
"Title" VARCHAR(160) NOT NULL, | |
"ArtistId" INT NOT NULL, | |
CONSTRAINT "PK_Album" PRIMARY KEY ("AlbumId") | |
); | |
CREATE TABLE "Artist" | |
( |
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
// Lazy evaluating | |
let newNumbersArray = [1, 2, 3, 4, 5] | |
let firstNumber = newNumbersArray.lazy.map({ $0 * 2 }).first! | |
print(firstNumber) |
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 numbers = [9, 14, 34, 46, 67] | |
// Imperative example [OOP] | |
var doubledNumbers = [Int]() | |
for number in numbers { | |
doubledNumbers.append(number * 2) | |
} | |
print(doubledNumbers) | |
// Declarative example [FP] |
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
// With for in loop | |
var agesSum = 0 | |
for user in queue { | |
agesSum += user.age | |
} | |
print(agesSum) | |
// With reduce method: |
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
// Using for in loop | |
var filteredUsers: [User] = [] | |
for user in queue { | |
print(user.age) | |
if user.age > 45 { | |
filteredUsers += [user] | |
} | |
} |
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
// With for in loop: | |
for user in queue { | |
print("Hi! My name is \(user.fullName) and I'm \(user.age) years old.") | |
} | |
// You can write as: | |
let newQueue = queue.map { (user: User) -> String in | |
return "Hi! My name is \(user.fullName) and I'm \(user.age) years old." | |
} | |
print(newQueue) |
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 User { | |
let id: Int | |
let fullName: String | |
let age: Int | |
init(id: Int, fullName: String, age: Int) { | |
self.id = id | |
self.fullName = fullName | |
self.age = age | |
} |
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
self.yourImageView.downloadImage("https://static.website.com/image_url.png") |
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
extension UIImageView { | |
func getDataFromUrl(url:String, completion: ((data: NSData?) -> Void)) { | |
NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: url)!) { (data, response, error) in | |
completion(data: NSData(data: data!)) | |
}.resume() | |
} | |
func downloadImage(url:String){ | |
getDataFromUrl(url) { data in | |
dispatch_async(dispatch_get_main_queue()) { |
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
func downloadImage(url:String){ | |
getDataFromUrl(url) { data in | |
dispatch_async(dispatch_get_main_queue()) { | |
self.contentMode = UIViewContentMode.ScaleAspectFill | |
self.image = UIImage(data: data!) | |
} | |
} | |
} |
NewerOlder