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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import LocalAuthentication | |
class AuthenticationViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
authenticateUser() | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
accountKit.logOut() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func viewController(viewController: UIViewController!, didCompleteLoginWithAccessToken accessToken: AKFAccessToken!, state: String!) { | |
print("did complete login with access token \(accessToken.tokenString) state \(state)") | |
} |
NewerOlder