Skip to content

Instantly share code, notes, and snippets.

View SergeyPetrachkov's full-sized avatar
:octocat:

Sergey Petrachkov SergeyPetrachkov

:octocat:
View GitHub Profile
gradientLayer.startPoint = CGPoint(x: 0, y: 1)
gradientLayer.endPoint = CGPoint(x: 0, y: 0)
/// Register settings bundle in the app
public func registerSettingsBundle() {
let appDefaults = [String: AnyObject]()
UserDefaults.standard.register(defaults: appDefaults)
}
/usr/libexec/PlistBuddy path_to/Settings.bundle/Root.plist -c "Clear"
/usr/libexec/PlistBuddy path_to/Services.plist -c "Clear"
class ViewController: ASViewController<ASScrollNode>, UIScrollViewDelegate {
let someFixedNode: ASDisplayNode = {
let node = ASDisplayNode()
node.backgroundColor = .red
node.style.height = ASDimension(unit: .points, value: 250)
return node
}()
let someFlexibleNode: ASDisplayNode = {
let node = ASDisplayNode()
public struct InviteFeedModel: Codable {
public var level: Int?
public var performerId: String
public var performerName: String?
public var newParticipantId: String?
public var newParticipantName: String?
public init(level: Int?, performerId: String, performerName: String?, newParticipantId: String?, newParticipantName: String?) {
self.level = level
@SergeyPetrachkov
SergeyPetrachkov / SwaggerApiResponseHandler.swift
Created April 23, 2019 08:00
Swagger helper with generic requestData
enum ServiceError: Error {
case timeout
case nilData
}
extension SwaggerClientAPI {
private enum HeadersKeys: String {
case authorization = "Authorization"
}
class func setBearer(_ token: String) {
{
"current_page": 1,
"data": [
{
"type": "draft",
"source": "subscribe",
"trainings_count": 10,
"created_at": "2019-04-23 17:10:42",
"trainings": [
{
@SergeyPetrachkov
SergeyPetrachkov / ChangeRoot.swift
Created November 29, 2019 12:49
ChangeRoot.swift
extension UIWindow {
/// Fix for http://stackoverflow.com/a/27153956/849645
func set(rootViewController newRootViewController: UIViewController,
withTransition transition: CATransition? = nil) {
let previousViewController = rootViewController
if let transition = transition {
// Add the transition
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
switch authorization.credential {
case let appleIDCredential as ASAuthorizationAppleIDCredential:
if let identityToken = appleIDCredential.identityToken,
let token = String(data: identityToken, encoding: .utf8),
let decodedToken = try? decode(jwt: token) {
// do your thing here
} else {
// something went wrong, handle it
}
@SergeyPetrachkov
SergeyPetrachkov / handleAuthorizationAppleIDButtonPress.swift
Created June 19, 2020 13:53
handleAuthorizationAppleIDButtonPress
@available(iOS 13.0, *)
@objc
private func handleAuthorizationAppleIDButtonPress() {
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]
let authorizationController = ASAuthorizationController(authorizationRequests: [request])
authorizationController.delegate = self
authorizationController.presentationContextProvider = self