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
def parse_soup_to_simple_html(self): | |
news_list = self.__soup.find_all(['h1', 'h2']) # h1 | |
#print (news_list) | |
htmltext = ''' | |
<html> | |
<head><title>Simple News Link Scrapper</title></head> | |
<body> | |
{NEWS_LINKS} |
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 readDesc(_ desc:inout String) throws { | |
let newDesc = desc | |
defer { | |
desc = "" | |
} | |
throw SampleError.sample2(message: "cool error") | |
print(newDesc) | |
} | |
var desc = "Life is cool and play is a tool!" |
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 square(val:Int) throws -> Int { | |
if val == 5 { | |
throw SampleError.sample1 | |
} | |
return val * val | |
} | |
let sqaureValue = try! square(val: 10) | |
print(sqaureValue) |
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 str = try? sampleThrowError() | |
if let str = str { | |
print(str) | |
} | |
else { | |
print("Str is nil") | |
} |
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
do { | |
try sampleThrowError() | |
} | |
catch SampleError.sample1 { | |
print("Sample 1 Error caught") | |
} | |
catch { | |
print("For all other cases") | |
} |
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 sampleThrowError() throws -> String { | |
throw SampleError.sample1 | |
return "" | |
} |
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
enum SampleError: Error { | |
case sample1 | |
case sample2(message: String) | |
} |
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
import UIKit | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
let pairOfNumbers = [(2, 3), (5, 10), (4, 5)] | |
let operationQueue = OperationQueue() | |
//if set 1, it will be serial if commented it will be concurrent | |
operationQueue.maxConcurrentOperationCount = 1 |
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 pairOfNumbers = [(2, 3), (5, 10), (4, 5)] | |
class MultiplcationOp : Operation{ | |
var inputPair: [(Int, Int)]? | |
override func main() { | |
guard let inputPair = inputPair else { return } | |
for pair in inputPair{ | |
let result = pair.0 * pair.1 | |
print(result) |
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
//Single BlockOperation | |
var result:Int? | |
let multiplication = BlockOperation{ | |
result = 5 * 10 | |
} | |
multiplication.start() | |
result | |
[/code] | |
Multiple operations using BlockOperation: |