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 piCalc(_ totalPoints: Int) -> Double { | |
var nPointsInside = 0 | |
for _ in 1...totalPoints { | |
let (x, y) = (drand48() * 2 - 1, drand48() * 2 - 1) | |
if x * x + y * y <= 1 { | |
nPointsInside += 1 | |
} | |
} | |
return 4.0 * Double(nPointsInside) / Double(totalPoints) | |
} |
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
#insert after all pods declaring (just put at the bottom of a file) | |
post_install do |installer| | |
installer.pods_project.targets.each do |target| | |
if target.name == 'POD_NAME_HERE' | |
target.build_configurations.each do |config| | |
config.build_settings['SWIFT_VERSION'] = '4.0' | |
end | |
end | |
end | |
end |
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 printRoots(a: Double, b: Double, c: Double, showImaginaryRoots: Bool = false) { | |
let b2 = b * b | |
let disc = b2 - (4 * a * c) | |
let discSqrt = sqrt(fabs(disc)) | |
let isImage = disc < 0 | |
let result = b * b - 4.0 * a * c |
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
// | |
// FMBlurable.swift | |
// FMBlurable | |
// | |
// Created by SIMON_NON_ADMIN on 18/09/2015. | |
// Copyright © 2015 Simon Gladman. All rights reserved. | |
// | |
// Thanks to romainmenke (https://twitter.com/romainmenke) for hint on a larger sample... | |
import UIKit |
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 resolveFirebaseObject<T: Codable>(_ snapshot: DocumentSnapshot) -> T? { | |
guard snapshot.exists else {return nil} | |
if let data = try? JSONSerialization.data(withJSONObject: snapshot.data(), options: []) { | |
do { | |
return try self.decoder.decode(T.self, from: data) | |
} catch { | |
print("Decoding error: \(error)") | |
} | |
} | |
return 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
struct ColorSliderView: View { | |
//Picked Color | |
@State | |
private var location: CGPoint = CGPoint(x: 0, y: 0) { | |
didSet { | |
//Need https://gist.githubusercontent.com/marchinram/3675efc96bf1cc2c02a5/raw/ec95113fa3cf1a6e97361426dc7574d9e14a09c0/UIImage+PixelColor.swift | |
currentColor = trackImage[Int(location.x), 0] ?? .white |
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
//We have a UICollectionView with Grid layout that shows a collection card. | |
//Model for a card looks like this: | |
struct CollectionViewCellModel: Codable { | |
let id: Int | |
let image: String | |
let imageUrl: String | |
let name: String | |
let description: String | |
let stocksAmount: Int |
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
//Setting the script | |
extension WebViewCoordinator: WKNavigationDelegate { | |
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | |
let script = """ | |
function isContentFullyRendered() { | |
var imgElements = document.images; | |
var imgComplete = true; | |
for (var i = 0; i < imgElements.length; i++) { | |
if (!imgElements[i].complete) { | |
imgComplete = false; |
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
//This class demostates how to extract and store payload info if it's available. Compaign ID was valuable for me so that's why only it is stored. | |
import AdServices | |
actor UTMCampaignLoader { | |
// Optional campaignID property | |
var campaignID: Int? | |
// Method to load UTM campaign asynchronously | |
func loadUTMCampaign() async -> Int? { |