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 Sequence { | |
func sorted<T: Comparable>(by keyPath:KeyPath<Element, T>) -> [Element]{ | |
return sorted {a, b in | |
return a[keyPath: keyPath] < b[keyPath:keyPath] | |
} | |
} | |
func map <T> (_ keyPath: KeyPath<Element, T>) -> [T] { | |
return map {$0[keyPath: keyPath]} | |
} |
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 SwiftUI | |
struct ArcView: View { | |
var body: some View { | |
Arc(startAngle: .degrees(0), endAngle: .degrees(110), clockwise: true) | |
.stroke(Color.blue, lineWidth: 5) | |
.frame(width: 300, height: 300, alignment: .center) | |
} | |
} |
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 SwiftUI | |
struct ToastView: View { | |
@State private var liked: Bool = false | |
var body: some View { | |
VStack { | |
LikeButton(liked: $liked) | |
} | |
.toast(isShowing: $liked, text: Text("Hello toast!")) |
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 SwiftUI | |
struct TriangleView: View { | |
static let gradientStart = Color(red: 239.0 / 255, green: 120.0 / 255, blue: 221.0 / 255) | |
static let gradientEnd = Color(red: 239.0 / 255, green: 172.0 / 255, blue: 120.0 / 255) | |
var body: some View { | |
Triangle() | |
.fill(LinearGradient( | |
gradient: .init(colors: [Self.gradientStart, Self.gradientEnd]), | |
startPoint: .init(x: 0.5, y: 0), |
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
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { | |
NSUInteger dataLength = deviceToken.length; | |
const unsigned char *dataBuffer = (const unsigned char *)deviceToken.bytes; | |
NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)]; | |
for (int i = 0; i < dataLength; ++i) { | |
[hexString appendFormat:@"%02x", dataBuffer[i]]; | |
} | |
let token = [hexString copy]; | |
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
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
export PS1="\h:\W:\$(parse_git_branch)$" |
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 Foundation | |
import UIKit | |
struct DeviceInfos { | |
static let IS_IPAD = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad) | |
static let IS_IPHONE = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.phone) | |
static let IS_RETINA = (UIScreen.main.scale >= 2.0) | |
static let SCREEN_WIDTH = (UIScreen.main.bounds.size.width) | |
static let SCREEN_HEIGHT = (UIScreen.main.bounds.size.height) | |
static let SCREEN_MAX_LENGTH = SCREEN_WIDTH >= SCREEN_HEIGHT ? SCREEN_WIDTH : SCREEN_HEIGHT | |
static let SCREEN_MIN_LENGTH = SCREEN_WIDTH <= SCREEN_HEIGHT ? SCREEN_WIDTH : SCREEN_HEIGHT |
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
textlabel.adjustsFontSizeToFitWidth = true | |
textlabel.minimumScaleFactor = 0.5 |
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 NSMutableDictionary { | |
func isExist(forKey key: String) -> Bool { | |
return self[key] != nil | |
} | |
func isKeyValue<T: Equatable> (value: T, forKey key: String) -> Bool { | |
if(!isExist(forKey: key)){ | |
return false | |
} | |
let val = self[key] as! T | |
return val == value |
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 KeyChainManager { | |
static func saveGenericPassword(service:String, account:String, password:String) -> Void { | |
let account = userNameTextField.text | |
let passwordUtf8 = password.data(using: String.Encoding.utf8)! | |
let addquery: [String: Any] = [kSecClass as String: kSecClassGenericPassword, | |
kSecAttrAccount as String: account!, | |
kSecAttrService as String: service , | |
kSecValueData as String: passwordUtf8!] | |
NewerOlder