Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Artur Rymarz artrmz

🎯
Focusing
View GitHub Profile
View CoreData.swift
// 1
@objc(Article)
// 2
final class Article: NSManagedObject {
// 3
@NSManaged var title: String
@NSManaged var content: String
}
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 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 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 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 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 ViewController.swift
private func donate(name: String) {
// 1
let intent = CheckMyGitHubIntent()
// 2
intent.suggestedInvocationPhrase = "Check my GitHub"
intent.name = name
// 3
let interaction = INInteraction(intent: intent, response: nil)
View Watermaniac.dart
@override
void paint(Canvas canvas, Size size) {
Paint paint = new Paint()
..color = Color(0xFFc7d0df)
..strokeWidth = 6.0
..strokeCap = StrokeCap.round
..style = PaintingStyle.stroke;
canvas.drawLine(Offset(0.0, 6.0), Offset(size.width * 0.15, size.height - 6.0), paint);
canvas.drawLine(Offset(0.0, 6.0), Offset(size.width, 6.0), paint);
View database_manager.dart
void insert(List<DatabaseModel> models) async {
var db = await database;
var batch = db.batch();
for (var model in models) {
DatabaseTable table = _tables[model.runtimeType];
if (table == null) {
return;
}
batch.insert(table.name, model.toMap());
View container_wrapper.dart
class ContainerWrapper extends StatelessWidget {
final Widget child;
final double widthScale;
ContainerWrapper({@required this.child, this.widthScale = 0.8});
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
return SizedBox(
You can’t perform that action at this time.