Skip to content

Instantly share code, notes, and snippets.

View Tulakshana's full-sized avatar

Tula Tulakshana

View GitHub Profile
@Tulakshana
Tulakshana / FYISession.swift
Last active November 25, 2020 09:42
Saving custom objects in NSUserDefaults - Swift
import Foundation
class FYISession {
let savedUserKey = "savedUser"
static let sharedInstance = FYISession()
var user:FYIUser = FYIUser(userId: 0, userMobile: "", userEmail: "", userName: "")
func userLoggedIn() -> Bool{
@Tulakshana
Tulakshana / SharedMethods.h
Last active February 26, 2016 08:22
A function to log all the fonts installed. This will list out the custom fonts included in the build as well. Address the fonts with the same name printed here when applying to UI components. Sometimes the font name is different from the file name.
- (void)printInstalledFonts;
@Tulakshana
Tulakshana / GMInteractiveMarker.swift
Last active April 6, 2016 08:41
An interactive Google Map with custom interactive markers
import UIKit
import GoogleMaps
class GMInteractiveMarker: UIViewController,GMSMapViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.loadMap()
@Tulakshana
Tulakshana / NSString+DateFormatter.h
Last active November 2, 2017 11:11
NSString category (Objective C) and String extension (Swift) to format date
#import <Foundation/Foundation.h>
@interface NSString (DateFormatter)
- (NSString *)dateStringFromFormat:(NSString *)fromFormat toFormat:(NSString *)toFormat;
@end
@Tulakshana
Tulakshana / TFunWithAlgorithms.swift
Created July 5, 2016 03:12
A simple set of functions I wrote when having fun with algorithms
//A function that could be called recursively to calculate the total of an integer array.
func total(array:NSArray,index:Int,sum:Int) -> Int {
if (index > (array.count - 1)) {
return sum
}else {
let currentNumber:Int = array.objectAtIndex(index) as! Int
let currentTotal:Int = sum + currentNumber
return total(array, index: index + 1, sum: currentTotal)
}
@Tulakshana
Tulakshana / crashlyticsDistribution.sh
Last active September 1, 2016 05:30
Run this script in a post integration trigger to distribute the latest build as a beta release to crashlytics. The script assumes that you have integrated crashlytics through cocoa pods. The script also extracts the latest commit message of the git branch and adds it as the release note.
cd "${XCS_SOURCE_DIR}/<project directory name>"
git log -1 --pretty=%B > "releaseNote.txt"
"Pods/Crashlytics/submit" <key> <secret> \
-notesPath "releaseNote.txt" \
-ipaPath "${XCS_PRODUCT}" -groupAliases <your distribution group> \
-notifications YES
@Tulakshana
Tulakshana / buildNumberChangeScript.txt
Created September 12, 2016 09:29
Xcode server run script to be run before integration to set the integration number as the build number.
//Prior to running the script below change build settings as mentioned in https://developer.apple.com/library/ios/qa/qa1827/_index.html
cd "${XCS_SOURCE_DIR}/Writer"
xcrun agvtool new-version -all "${XCS_INTEGRATION_NUMBER}"
@Tulakshana
Tulakshana / MyAPI.swift
Last active April 20, 2023 12:31
Handling re-direction with URLSession (Swift)
import UIKit
@objc class MyAPI: NSObject {
static let keyError: String = "Error"
static let keyResult: String = "Result"
static let unknownError: String = "Unknown error"
static let notificationMyAPIDidEnd = Notification.Name(rawValue: "notificationMyAPIDidEnd")
@Tulakshana
Tulakshana / URICoder
Created June 8, 2017 12:28
This method will mimic javascript function "encodeURIComponent(<string to be encoded>)" in Objective C
+ (NSString *) encodeString: (NSString *) string {
NSMutableString *output = [NSMutableString string];
const unsigned char *source = (const unsigned char *)[string UTF8String];
int sourceLen = (int)strlen((const char *)source);
for (int i = 0; i < sourceLen; ++i) {
const unsigned char thisChar = source[i];
if (thisChar == ' '){
[output appendString:@"%20"];
} else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
@Tulakshana
Tulakshana / AttribManipulator.swift
Last active October 17, 2017 13:09
A convenience method create an attributed string from a plain html string and apply a font of your choice. The method could be modified to support any fonts and styles.
enum FontName: String {
case timesNewRoman = "TimesNewRomanPSMT"
case timesNewRomanItalic = "TimesNewRomanPS-ItalicMT"
case timesNewRomanBold = "TimesNewRomanPS-BoldMT"
}
extension UIFont {
class var sanFranciscoRegular: UIFont {
if let font = UIFont.init(name: "SFUIText-Regular", size: 15) {