Skip to content

Instantly share code, notes, and snippets.

View anas-p's full-sized avatar
🎯
Focusing

Anas Poovalloor anas-p

🎯
Focusing
View GitHub Profile
@anas-p
anas-p / When to Use Generics vs Associated Types.md
Last active January 29, 2025 12:52
When to Use Generics vs Associated Types
Generics Associated Types
Used in concrete types (structs, classes, functions). Used in protocols to define placeholder types.
Ideal for reusable algorithms or data structures. Ideal for defining flexible behavior in protocols.
Example: Array< T >, Dictionary. Example: CarrierRobot with Item.
@anas-p
anas-p / demonstrate_async_let.swift
Created September 23, 2024 15:35
Demonstrate async let
import Foundation
// Mock function to simulate network call for fetching user data
func fetchUserData() async -> String {
print("Fetching user data...")
try? await Task.sleep(nanoseconds: 2_000_000_000) // Simulates a 2 second delay
return "User: John Doe"
}
// Mock function to simulate network call for fetching user orders
@anas-p
anas-p / gist:c05f78c72642a8f84f4da1545728c8da
Last active April 29, 2019 14:40 — forked from steipete/ios-xcode-device-support.sh
Using iOS 12.2 devices with Xcode 10.1
// The trick is to link the DeviceSupport folder from the beta to the stable version.
// Updated on Feb 15th, 2019 for Xcode 10.1
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/12.2\ \(16E5191d\) /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
// Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
// sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
@anas-p
anas-p / AuthenticationViewController.swift
Created April 23, 2019 08:57
Implementing Touch ID and Face ID Authentication in iOS
import UIKit
import LocalAuthentication
class AuthenticationViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
authenticateUser()
}
@anas-p
anas-p / UIButton-with-center-aligned-icon-and-bottom-text.swift
Created November 16, 2018 11:14
UIButton with center aligned icon and bottom text
extension UIButton {
// Center aligned icon and bottom text
func centerVertically(padding: CGFloat = 6.0) {
guard
let imageViewSize = self.imageView?.frame.size,
let titleLabelSize = self.titleLabel?.frame.size else {
return
}
self.imageEdgeInsets = UIEdgeInsets(
@anas-p
anas-p / accountKit_logOut.swift
Created May 14, 2018 13:33
Facebook Account Kit using Swift
accountKit.logOut()
@anas-p
anas-p / access_account_info.swift
Created May 14, 2018 13:32
Facebook Account Kit using Swift
if accountKit == nil {
//specify AKFResponseType.AccessToken
self.accountKit = AKFAccountKit(responseType: AKFResponseType.accessToken) accountKit.requestAccount {
(account, error) -> Void in
if let accountID = account?.accountID{
self.lblAccountId.text = accountID
}
if let email = account?.emailAddress {
self.lblEmailOrPhone.text = email
@anas-p
anas-p / handle_failed_cancel.swift
Created May 14, 2018 13:30
Facebook Account Kit using Swift
func viewController(_ viewController: (UIViewController & AKFViewController)!, didFailWithError error: Error!) {
// ... implement appropriate error handling ...
print("\(viewController) did fail with error: \(error.localizedDescription)")
}
func viewControllerDidCancel(_ viewController: (UIViewController & AKFViewController)!) {
// ... handle user cancellation of the login process ...
}
@anas-p
anas-p / handle_authorization_code.swift
Created May 14, 2018 13:29
Facebook Account Kit using Swift
func viewController(_ viewController: (UIViewController & AKFViewController)!, didCompleteLoginWithAuthorizationCode code: String!, state: String!) {
//...
}
@anas-p
anas-p / handle_access_token.swift
Created May 14, 2018 13:28
Facebook Account Kit using Swift
func viewController(viewController: UIViewController!, didCompleteLoginWithAccessToken accessToken: AKFAccessToken!, state: String!) {
print("did complete login with access token \(accessToken.tokenString) state \(state)")
}