Skip to content

Instantly share code, notes, and snippets.

View mehdin13's full-sized avatar

Mehdi Negahban mehdin13

View GitHub Profile
@cemolcay
cemolcay / ArcTextLayer.swift
Created January 22, 2017 22:03
Draws a curved string on a CALayer with angle, radius and text that you give.
import UIKit
// swift port of stackoverflow answer
// http://stackoverflow.com/a/31301238/2048130
extension CGFloat {
/** Degrees to Radian **/
var degrees: CGFloat {
return self * (180.0 / .pi)
}
@mikoim
mikoim / README.md
Last active March 30, 2025 06:04
[Updated! Aug 14 2020] YouTube recommended encoding settings on ffmpeg (+ libx264)

Parameters

Container: MP4

Parameter YouTube recommends setting
-movflags faststart moov atom at the front of the file (Fast Start)

Video codec: H.264

@IamAlchemist
IamAlchemist / datepicker.swift
Created October 10, 2016 03:07
a date picker in alert view
@IBAction func selectDate(_ sender: UIButton) {
let datePicker = UIDatePicker()
datePicker.datePickerMode = .date
let alert = UIAlertController(title: "\n\n\n\n\n\n\n\n\n\n\n", message: nil, preferredStyle: .actionSheet)
alert.view.addSubview(datePicker)
datePicker.snp.makeConstraints { (make) in
make.centerX.equalTo(alert.view)
make.top.equalTo(alert.view).offset(8)
@lvterry
lvterry / getAssetThumbnail.swift
Created March 28, 2016 14:57
Convert PHAsset to UIImage with Swift
// it returns a square thumbnail.
func getAssetThumbnail(asset: PHAsset, size: CGFloat) -> UIImage {
let retinaScale = UIScreen.mainScreen().scale
let retinaSquare = CGSizeMake(size * retinaScale, size * retinaScale)
let cropSizeLength = min(asset.pixelWidth, asset.pixelHeight)
let square = CGRectMake(0, 0, CGFloat(cropSizeLength), CGFloat(cropSizeLength))
let cropRect = CGRectApplyAffineTransform(square, CGAffineTransformMakeScale(1.0/CGFloat(asset.pixelWidth), 1.0/CGFloat(asset.pixelHeight)))
let manager = PHImageManager.defaultManager()
@AdityaDeshmane
AdityaDeshmane / iOS: Full name search using predicate
Created February 18, 2016 16:13
iOS: Full name search using predicate
-(NSArray*) dataSourceForSearchString:(NSString*) searchedText
{
NSString *strTrimmedSearchText = [searchedText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSArray *array = [strTrimmedSearchText componentsSeparatedByString:@" "];
NSPredicate *predicate = nil;
/*
@gblancogarcia
gblancogarcia / AppDelegate.swift
Last active January 27, 2023 18:00
Core Data: preloading an existing SQLite database
import UIKit
import CoreData
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
return true
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface VisualizerView : UIView
@property (strong, nonatomic) AVAudioPlayer *audioPlayer;
@property (nonatomic, assign) NSInteger numberOfBars;
@end
@MihaelIsaev
MihaelIsaev / CameraViewController.swift
Created April 16, 2015 19:30
This is the example of camera view for iOS written in Swift
import UIKit
import AVFoundation
class ViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
@IBOutlet weak var myView: UIView!
var session: AVCaptureSession?
var device: AVCaptureDevice?
var input: AVCaptureDeviceInput?
@benvium
benvium / MyTabBar.m
Created March 5, 2015 11:22
UITabBarController slide animation. Slide left and right when tabs are selected. Based on code from StackOverflow (linked in code)
- (BOOL) tabBarController:(UITabBarController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController {
// http://stackoverflow.com/questions/5161730/iphone-how-to-switch-tabs-with-an-animation
NSUInteger controllerIndex = [self.viewControllers indexOfObject:viewController];
if (controllerIndex == tabBarController.selectedIndex) {
return NO;
}
@jpotts18
jpotts18 / Alamofire-JSON-Serialization.md
Last active August 17, 2020 15:44
Alamofire JSON Serialization of Objects, Collections, Nesting

Alamofire JSON Serialization of Objects and Collections

Alamofire is a great Swift library developed by the creator of AFNetworking @mattt. The purpose of this gist is to explain how to use the built-in power of Alamofire to serialize your JSON. In this example we will be serializing a simple blog API. First we will start with serializing a single JSON object and add complexity as we go along.

Warning: This was written before Swift 1.2

A Single JSON Serialization

This is the first JSON object that we will be serializing.