Skip to content

Instantly share code, notes, and snippets.

View mspvirajpatel's full-sized avatar
🏠
Working from home

Virajkumar Patel mspvirajpatel

🏠
Working from home
View GitHub Profile
@mspvirajpatel
mspvirajpatel / ImageUpload.Swift
Created September 8, 2017 07:31
Try This Code for Multiple upload Images in Single Request, This code is already working.
// For Pass Valid Parameters & number of Images in Array in Image Upload Function
var dicImgData : NSMutableDictionary? = NSMutableDictionary()
if let img = UIImage(named: "Your Image") {
if let data:Data = UIImagePNGRepresentation(img) {
var imageData : NSData = data
dicImgData! .setObject(imageData, forKey: "data" as NSCopying)
dicImgData! .setObject("file", forKey: "name" as NSCopying)
dicImgData! .setObject("file.png", forKey: "fileName" as NSCopying)
@mspvirajpatel
mspvirajpatel / BaseScrollViewController.swift
Last active August 25, 2018 17:28
Smooth UIScrollView with custom paging in Swift 3.0.
import UIKit
public protocol ContainerViewControllerDelegate {
func outerScrollViewShouldScroll() -> Bool
}
public class BaseScrollViewController: UIViewController, UIScrollViewDelegate {
public var topVc: UIViewController?
public var leftVc: UIViewController!
@mspvirajpatel
mspvirajpatel / GoogleAdsMob.swift
Created September 14, 2017 13:48
Easily integration banner and interstitial GoogleMobileAds in swift project.
import UIKit
import GoogleMobileAds
//MARK: - Google Ads Unit ID
struct GoogleAdsUnitID {
//Google Test Unit ID
struct Test {
static var strBannerAdsID = "ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXXX"
static var strInterstitialAdsID = "ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXXX"
func uploadGoogleURL(imageName: String,contents : String,parentsFolderId : String?) {
self.showProgressHUD(viewController: self, title: "uploadImage".localize(), subtitle: "")
let metadata = GTLRDrive_File.init()
metadata.name = imageName
if parentsFolderId != nil
{
let folderId: String = parentsFolderId!
metadata.parents = [folderId]
}
@mspvirajpatel
mspvirajpatel / APIManager.h
Last active September 22, 2017 09:33
API Call Manager Class Objective C
#import <Foundation/Foundation.h>
typedef NS_OPTIONS(NSInteger, APITask){
Login = 0,
Register = 1
};
@interface APIManager : NSObject
@mspvirajpatel
mspvirajpatel / ViewController.swift
Created February 19, 2018 03:59
Animate text change in UILabel (Label Fade Animation)
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel!
var count = 0
@IBAction func doAction(_ sender: UIButton) {
// This will fade:
label.fadeTransition(0.4)
count += 1
label.text = "\(count)"
@mspvirajpatel
mspvirajpatel / IBInspectable.Swift
Created February 21, 2018 10:01
How to create an IBInspectable of type enum
enum StatusShape:Int {
case Rectangle
case Triangle
case Circle
}
// Programmatically: use the enum
var shape:StatusShape = .Rectangle
// IB: use the adapter
extension UIImage {
enum CompressImageErrors: Error {
case invalidExSize
case sizeImpossibleToReach
}
func compressImage(_ expectedSizeKb: Int, completion : (UIImage,CGFloat) -> Void ) throws {
// Media is a video
let videoUrl = "Your URL FILE" as! NSURL
let asset = AVAsset(url: videoUrl as URL)
let first: CMTimeRange = CMTimeRange.init(start: kCMTimeZero, duration: CMTime.init(seconds: 2, preferredTimescale: asset.duration.timescale))
let firstScael: CMTime = CMTimeMakeWithSeconds((Float64(2) * Float64(5)), asset.duration.timescale)
let second: CMTimeRange = CMTimeRange.init(start: CMTime.init(seconds: 5, preferredTimescale: asset.duration.timescale), duration: CMTime.init(seconds: 5, preferredTimescale: asset.duration.timescale))
let secondScael: CMTime = CMTimeMakeWithSeconds((Float64(5) / Float64(5.0)), asset.duration.timescale)
@mspvirajpatel
mspvirajpatel / RPScreenWriter.swift
Created June 10, 2019 06:25
ScreenWriter With ReplayKit
import Foundation
import AVFoundation
import ReplayKit
class RPScreenWriter {
// Write video
var videoOutputURL: URL
var videoWriter: AVAssetWriter?
var videoInput: AVAssetWriterInput?
// Write audio