Skip to content

Instantly share code, notes, and snippets.

View ptvyas's full-sized avatar

Piyush Vyas ptvyas

  • Surat, Gujarat, India
  • 15:46 (UTC +05:30)
  • X @vyas_pt
View GitHub Profile
@oguzhanvarsak
oguzhanvarsak / questions.md
Last active April 18, 2024 18:50
Interview Questions for iOS Developers

Interview Questions for iOS Developers

1. Classes vs structs

In Swift, structs are value types whereas classes are reference types. When you copy a struct, you end up with two unique copies of the data. When you copy a class, you end up with two references to one instance of the data. It’s a crucial difference, and it affects your choice between classes or structs. (+ Class extendable, struct does not.)

2. What’s the difference between var and let? Which one would you choose for properties in a struct and why?

Both let and var are for creating variables in Swift. let helps you create immutable variables (constants) while on the other hand var creates mutable variables.

3. What does the mutating keyword mean?

The mutating keyword lets callers know that the method is going to make the value change.

import UIKit
infix operator |: AdditionPrecedence
public extension UIColor {
struct App {
static let hyperLink = UIColor.colorWithHex(hex: "#FFFFFF")
static let background = UIColor.white | UIColor.black
}
func createThumbnailOfVideoFromRemoteUrl(url: String) -> UIImage? {
let asset = AVAsset(url: URL(string: url)!)
let assetImgGenerate = AVAssetImageGenerator(asset: asset)
assetImgGenerate.appliesPreferredTrackTransform = true
//Can set this to improve performance if target size is known before hand
//assetImgGenerate.maximumSize = CGSize(width,height)
let time = CMTimeMakeWithSeconds(1.0, 600)
do {
let img = try assetImgGenerate.copyCGImage(at: time, actualTime: nil)
let thumbnail = UIImage(cgImage: img)
@mansi-27
mansi-27 / UIView+Extensions
Created February 22, 2018 18:02
Sets border to the UIView
extension UIView {
/// Sets border to the UIView
func setViewBorder(withWidth width: CGFloat = 1.0, color: UIColor) {
self.layer.borderWidth = width
self.layer.borderColor = color.cgColor
}
}
@mansi-27
mansi-27 / UIView+Extensions
Created February 22, 2018 18:01
Produce vertical shake animation
extension UIView {
/// Produce vertical shake animation
func shakeVertically(withCount count: Float = 4, duration: TimeInterval = 0.3, translation: Float = -10) {
let animation: CABasicAnimation = CABasicAnimation(keyPath: "transform.translation.y")
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.repeatCount = count
animation.duration = (duration)/TimeInterval(animation.repeatCount)
animation.autoreverses = true
@mansi-27
mansi-27 / UIView+Extensions
Created February 22, 2018 18:00
Sets rounded corners to the UIView
extension UIView {
/// Sets rounded corners to the UIView
func roundedCorners(radius: CGFloat? = nil) {
if let radius = radius {
layer.cornerRadius = radius
} else {
layer.cornerRadius = frame.size.height / 2
}
clipsToBounds = true
@mansi-27
mansi-27 / UIView+Extensions
Last active April 30, 2018 07:18
Produce horizontal shake animation
extension UIView {
/// Produce horizontal shake animation
func shakeHorizontally(withCount count: Float = 4, duration: TimeInterval = 0.3, translation: Float = -10) {
let animation: CABasicAnimation = CABasicAnimation(keyPath: "transform.translation.x")
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.repeatCount = count
animation.duration = (duration)/TimeInterval(animation.repeatCount)
animation.autoreverses = true
extension UIImage {
func blurred(radius: CGFloat) -> UIImage {
let ciContext = CIContext(options: nil)
guard let cgImage = cgImage else { return self }
let inputImage = CIImage(cgImage: cgImage)
guard let ciFilter = CIFilter(name: "CIGaussianBlur") else { return self }
ciFilter.setValue(inputImage, forKey: kCIInputImageKey)
ciFilter.setValue(radius, forKey: "inputRadius")
guard let resultImage = ciFilter.value(forKey: kCIOutputImageKey) as? CIImage else { return self }
//
// StandardTooltip.swift
//
// Created by Albert Bori on 11/20/17.
//
import Foundation
@objc
class StandardTooltip: NSObject {
@eleev
eleev / URLForPHAsset.swift
Last active February 17, 2024 23:56
Getting URL for PHAsset (Swift 3.0)
func getURL(ofPhotoWith mPhasset: PHAsset, completionHandler : @escaping ((_ responseURL : URL?) -> Void)) {
if mPhasset.mediaType == .image {
let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions()
options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData) -> Bool in
return true
}
mPhasset.requestContentEditingInput(with: options, completionHandler: { (contentEditingInput, info) in
completionHandler(contentEditingInput!.fullSizeImageURL)
})