Skip to content

Instantly share code, notes, and snippets.

Artur Rymarz artrmz

Block or report user

Report or block artrmz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View IntentViewController.swift
class IntentViewController: UIViewController, INUIHostedViewControlling {
@IBOutlet weak var reposLabel: UILabel!
@IBOutlet weak var followersLabel: UILabel!
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!
// MARK: - INUIHostedViewControlling
// Prepare your view controller for the interaction to handle.
func configureView(for parameters: Set<INParameter>, of interaction: INInteraction, interactiveBehavior: INUIInteractiveBehavior, context: INUIHostedViewContext, completion: @escaping (Bool, Set<INParameter>, CGSize) -> Void) {
View GitHubUserIntentHandler.swift
final class CheckMyGitHubIntentHandler: NSObject, CheckMyGitHubIntentHandling {
func handle(intent: CheckMyGitHubIntent, completion: @escaping (CheckMyGitHubIntentResponse) -> Void) {
guard let name = intent.name else {
completion(CheckMyGitHubIntentResponse(code: .failure, userActivity: nil))
return
}
Fetcher.fetch(name: name) { (user, followers) in
guard let user = user else {
completion(CheckMyGitHubIntentResponse(code: .failure, userActivity: nil))
View IntentHandler.swift
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
guard intent is CheckMyGitHubIntent else {
fatalError("Unhandled intent type: \(intent)")
}
return CheckMyGitHubIntentHandler()
}
}
View Fetcher.swift
public final class Fetcher: NSObject {
public static func fetch(name: String, completion: @escaping ((user: GitHubUser?, followers: [GitHubFollower])) -> Void) {
guard let url = URL(string: "https://api.github.com/users/\(name)") else {
return
}
let request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 10.0)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard
View GitHub.swift
public struct GitHubUser: Codable {
public let name: String
public let location: String
public let repos: Int
private enum CodingKeys: String, CodingKey {
case name
case location
case repos = "public_repos"
}
View CoreData.swift
// 1
@objc(Article)
// 2
final class Article: NSManagedObject {
// 3
@NSManaged var title: String
@NSManaged var content: String
}
View CoreData.swift
private func deleteAllArticles() {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return
}
let context = appDelegate.persistentContainer.viewContext
// 1
let articles = loadArticles()
View CoreData.swift
private func loadArticles() -> [Article] {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return []
}
let context = appDelegate.persistentContainer.viewContext
// 1
let request: NSFetchRequest<Article> = Article.fetchRequest()
View CoreData.swift
private func saveSomeArticles() {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return
}
// 1
let context = appDelegate.persistentContainer.viewContext
// 2
let mediumArticle = Article(context: context)
View CoreData.swift
private func saveSomeArticles() {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return
}
}
You can’t perform that action at this time.