Skip to content

Instantly share code, notes, and snippets.

View Julioacarrettoni's full-sized avatar
🇦🇷

Julio Carrettoni Julioacarrettoni

🇦🇷
View GitHub Profile
@Julioacarrettoni
Julioacarrettoni / ContentView.swift
Last active February 16, 2022 03:15
Neumorphism in SwiftUI
/// This is a simple example of Neumorphism applied to buttons in SwiftUI
/// As seen on https://twitter.com/dev_jac/status/1228575575171723264
/// This should work straight out of the box, no other files are required
import SwiftUI
extension Color {
static let mainColor = Color(red: 224/255, green: 229/255, blue: 236/255)
static let mainColorActive = Color(red: 220/255, green: 225/255, blue: 232/255)
static let grayShadow = Color(red: 163/255, green: 177/255, blue: 198/255)
### Keybase proof
I hereby claim:
* I am julioacarrettoni on github.
* I am dev_jac (https://keybase.io/dev_jac) on keybase.
* I have a public key whose fingerprint is AE67 C01B BCF8 5591 662B 6765 F000 C442 1C88 09CF
To claim this, I am signing this object:
@Julioacarrettoni
Julioacarrettoni / weakSelfClosureTest.swift
Created August 17, 2017 14:22
Testing a weak self issue with nested closures reported by @manuelmaly
import Foundation
//https://twitter.com/manuelmaly/status/898141485228544000
class Foo {
var y: Int = 8
func bar() {
let b = { [weak self] in
let x = {
// self is nil here
return self?.y
}()
// First we need to take a look at the documentation
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
optional public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool // return NO to not change text
- TextField: The text field containing the text.
- range: The range of characters to be replaced.
- string: The replacement string for the specified range. During typing, this parameter normally contains only the single new character that was typed, but it may contain more characters if the user is pasting text. When the user deletes one or more characters, the replacement string is empty.
//So you actualy need to combine the actual text and the new string together, not just count the character, as for example the user might be replacing a chunk of text with another using "paste" or auto correct.
//Obj-C
- (BOOL)textField:(UITextField *)textField shouldChangeCharac
@Julioacarrettoni
Julioacarrettoni / Xcode and Cache Invalidation
Created February 9, 2017 17:50
Super weird errors on Xcode? Fix them with this easy trick!
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData
rm -rf ~/Library/Caches/com.apple.dt.Xcode
@Julioacarrettoni
Julioacarrettoni / lazyMapsAndFlatMaps.swift
Created December 22, 2015 21:35
Possible bug on Swift 2?
let array = [1, 2, 3, 4, 5, 6]
array.map { (value) -> [Int] in
print(value)
return [value]
}
array.lazy.map { (value) -> [Int] in
print("value: \(value)")
return [value]
@Julioacarrettoni
Julioacarrettoni / lazyFlatMap.swift
Created December 22, 2015 21:32
Playing with lazy and "real" flat maps
let mixedArray = [1, "2", 3, "4", 5, 6]
let resultA = mixedArray.flatMap({ $0 as? String })
resultA.first
let resultB = mixedArray.lazy.flatMap({ $0 as? String })
resultB.first
@Julioacarrettoni
Julioacarrettoni / MyPlayground.swift
Last active December 22, 2015 20:57
Playing with lazy collections and maps and flats and stuff… (and getting really really confused)
let array = [1, 2, 3, 4, 5, 6]
array.map { (value) -> [Int] in
print(value)
return [value]
}
array.lazy.map { (value) -> [Int] in
print("value: \(value)")
return [value+1]
// Extend UILabel with a method which sets font, to be used by UIAppearance
extension UILabel
{
func setFontName(fontName:String)
{
self.font = UIFont(name: fontName, size: self.font.pointSize)
}
}
// Somewhere in the code, call the extension method on the UIAppearance proxy object of UILabel, example:
@Julioacarrettoni
Julioacarrettoni / gist:1d44f8828b87e1705f88
Created August 20, 2014 19:23
An automatic URL to redime iOS App Store codes
https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/freeProductCodeWizard?code=