Skip to content

Instantly share code, notes, and snippets.

View Yoloabdo's full-sized avatar
:octocat:
Building another UIViewController

Abdoelrhman Yoloabdo

:octocat:
Building another UIViewController
View GitHub Profile
@Yoloabdo
Yoloabdo / ClosureViews.swift
Last active March 23, 2016 07:42
adding views to UIViewController
// outlet to the super view
@IBOutlet weak var gameView: UIView!
// creating your subview via lazy allows you to reach the gameView outlet after intializing, otherwise it wouldn't be there to reach
lazy var ball: UIView = {
let ballview = UIView(frame: CGRect(origin: CGPoint(x: self.gameView.bounds.midX, y: self.gameView.bounds.midY) , size: CGSize(width: 25, height: 25)))
ballview.backgroundColor = UIColor.blueColor()
ballview.layer.cornerRadius = 3
self.gameView.addSubView(ballview)
return ballview
@Yoloabdo
Yoloabdo / Arrays
Created August 21, 2016 21:39
Playing with arrays in Swift
// Fast.
Array.removeAtIndex(0)
//same job, a bit slower.
Array(edited.dropFirst())
// printing an Int array:
// MARK: - First method
let res = Array.map { String($0) }
print(res.joinWithSeparator(" "))
//MARK: - Second method
_ = leftShift(x, times: 4).map { print("\($0) ", terminator: "") }
@Yoloabdo
Yoloabdo / gist:e69f02e8cc4cfa016ad6c9c2251ae101
Created January 18, 2017 15:07
load more messages method
func loadMoreChatMessages() {
self.showLoadEarlierMessagesHeader = false
page += 1
let bottomOffset = self.collectionView.contentSize.height - self.collectionView.contentOffset.y
CATransaction.begin()
CATransaction.setDisableActions(true)
fetchChatData(false) {[unowned self] (_) in
if !self.historyMessages.isEmpty {
@Yoloabdo
Yoloabdo / gist:52edc4f16918bbdad80b84f5d655654c
Last active January 28, 2018 00:12 — forked from bwhiteley/gist:049e4bede49e71a6d2e2
Initialize Swift subclass of UIView, designed in .xib
// Create CustomView.xib, set File's Owner to CustomView.
// Link the top level view in the XIB to the contentView outlet.
class CustomView : UIView {
@IBOutlet private var contentView:UIView?
// other outlets
override init(frame: CGRect) { // for using CustomView in code
super.init(frame: frame)
self.commonInit()
@Yoloabdo
Yoloabdo / CircleView.swift
Created March 21, 2018 20:53
A circular view with fill for Swift 4 ios apps
// CircleView.swift
// OpenSource
//
// Created by abdelrahman mohamed on 2/13/18.
// Copyright © 2018 abdelrahman mohamed. All rights reserved.
//
import UIKit
@IBDesignable
@Yoloabdo
Yoloabdo / GradientView.swift
Created April 1, 2018 21:01
Gradient view for UIView - Swift 4.1
//
// GradientView.swift
//
// Created by abdelrahman mohamed on 3/19/18.
// Copyright © 2018 abdelrahman mohamed. All rights reserved.
//
import UIKit
@IBDesignable public class GradientView: UIView {
@Yoloabdo
Yoloabdo / URLRequestBuilder
Created May 31, 2018 00:47
Building URLRequest enum
import Foundation
import Alamofire
protocol URLRequestBuilder: URLRequestConvertible {
var mainURL: URL { get }
var requestURL: URL { get }
// MARK: - Path
var path: ServerPaths { get }
enum UserRequest: URLRequestBuilder {
case login(email: String, password: String)
case register(name: String, email: String, password: String, phone: String)
case userInfo
// MARK: - Path
internal var path: ServerPaths {
switch self {
case .login:
@Yoloabdo
Yoloabdo / ServerPaths
Created May 31, 2018 09:41
Server paths enum
enum ServerPaths: String {
case login
case register
case phoneActivation = "phone_activation"
case resendPhoneActivation = "resend_phone_activation_code"
case resendEmailLink = "send_reset_link_email"
case resetPassword = "reset_password"
case userInfo = "get_account_info"
case updateInfo = "update_account_info"
case userBalance = "get_user_internal_balance"