Skip to content

Instantly share code, notes, and snippets.

UIView.animateKeyframesWithDuration(0.6, delay: 0.0, options: UIViewKeyframeAnimationOptions.CalculationModeLinear, animations: {
UIView.setAnimationRepeatCount(3);
self.myconstraint.constant = 40
UIView.addKeyframeWithRelativeStartTime(0.0, relativeDuration: 0.3, animations: {
self.view.layoutIfNeeded()
})
self.myconstraint.constant = 30
UIView.addKeyframeWithRelativeStartTime(0.3, relativeDuration: 0.3, animations: {
@vigneshr89
vigneshr89 / ObjC-PartialAvailabilityCheck
Last active September 24, 2016 15:07
Partial API Availability check in Xcode
Problem:
Xcode does not create warnings when API introduced after "Deployment Target SDK Version" are used in the source code.
Some background information:
The APIs that are introduced after the deployment target version are weak imported by the llvm clang compiler in the binary to manage backward compatibility i.e, target device will run the new weak imported API if it is available (Think how you will access a weak variable in swift).
Hence if proper care is not taken, app will break at runtime.
In iOS and Mac OSX SDKs API availabilities are marked with a macro(ex:NS_AVAILABLE_IOS) defined in runtime header(NSObjRuntime.h) file.
Cocoapods
Jargons:
• Cocoapods
o It is a tool written in ruby to help with your pods
• Pod
o Pod is a simple ruby file to specify project dependencies.
@vigneshr89
vigneshr89 / DesginPattern.txt
Last active January 21, 2016 18:13
Design patterns in one lines
Design patterns
Behavioural: Deals with communication of objects
Chain-Of-Responsibility - Think of UIResponder class
Command pattern - NSInvocation class. Support undoable operations
Interpreter - language parsing. Think of expression evaluation
Iterator - NSEnumerator; A unified interface for interating a collection.
Mediator - Think of a translator's role in multi lingual people communication.
Memento - Think of a storing in the middle of a game and restore it.
observer - KVO.
@vigneshr89
vigneshr89 / NSURLSession Background service steps
Last active November 1, 2022 06:06
NSURLSession Background service steps
For a background download service with NSURLSession
1. Create a download task with background session configuration with NSURLSession delegates.
2. If, application is in foreground NSURLsession delegate will be called directly.
3. If application is background or killed additional methods are needed in the app delegate .
4. "handleEventsForBackgroundURLSession" will be called first, where it is necessary to reinstate the session object with the delegate again. Otherwise delegate methods will not be called.
5. "URLSessionDidFinishEventsForBackgroundURLSession" will be called once everything is done. You can decide what you want to do once the download is complete like updating the UI.
import UIKit
class ViewController: UIViewController {
/***
*
* This method explains a GCD based synchronization mechanism to protect a shared resource.
* In objective C - @synchronized(Object) directive on a object provides similar protection.
* Only one thread can enter a synchronized section on the object being locked.