Skip to content

Instantly share code, notes, and snippets.

View harrysummers's full-sized avatar

Harry Summers harrysummers

  • EBSCO Ind.
  • Birmingham AL
View GitHub Profile
@harrysummers
harrysummers / alamofireSolution.swift
Last active August 25, 2017 19:36
Alamofire with JSQMessagesViewController
import Foundation
import AlamofireImage
import JSQMessagesViewController
import NVActivityIndicatorView
class AsyncPhotoMediaItem: JSQPhotoMediaItem {
var asyncImageView: UIImageView!
var url : URL?
@harrysummers
harrysummers / JSQAndAlamofireAsync.swift
Created June 16, 2017 20:53
Using the AsyncPhotoMediaItem2
let imageView = AsyncPhotoMediaItem2(withURL: URL(string: mediaUrl)!)
if senderId == Auth.auth().currentUser!.uid {
newImg?.appliesMediaViewMaskAsOutgoing = true
} else {
newImg?.appliesMediaViewMaskAsOutgoing = false
}
self.messages.append(JSQMessage(senderId: senderId, senderDisplayName: displayName, date: timeStamp, media: imageView));
self.finishReceivingMessage()
@harrysummers
harrysummers / UITableViewCell
Created May 4, 2018 22:21
Example for a programmatic UITableViewCell
//
// AlbumsTableViewCell.swift
// InfiniteLibrary
//
// Created by Harry Summers on 5/4/18.
// Copyright © 2018 harrysummers. All rights reserved.
//
import UIKit
@harrysummers
harrysummers / gist:291131ce718268279e051125a1dd147e
Created May 11, 2018 22:17
NSFetchResultsController updateSearchResults
func updateSearchResults(for searchController: UISearchController) {
let searchText = searchController.searchBar.text ?? ""
var predicate: NSPredicate?
if searchText.count > 0 {
predicate = NSPredicate(format: "(name contains[cd] %@) || (artist.name contains[cd] %@)", searchText, searchText)
} else {
predicate = nil
}
fetchedResultsController.fetchRequest.predicate = predicate
@harrysummers
harrysummers / gist:954c1bae367a70281914ec357af97946
Last active May 11, 2018 22:58
Scroll to top on tab bar controller pressed
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
let topIndex = IndexPath(row: 0, section: 0)
if let navController = viewController as? UINavigationController,
navController.childViewControllers.count > 0 {
let childController = navController.childViewControllers[0]
if let vc = childController as? AlbumsTableViewController {
vc.tableView.scrollToRow(at: topIndex, at: .top, animated: true)
} else if let vc = childController as? ArtistsTableViewController {
vc.tableView.scrollToRow(at: topIndex, at: .top, animated: true)
}
@harrysummers
harrysummers / gist:d1470e0e9d8e45b4b45ec4b410822b24
Created May 12, 2018 21:44
Getting album id from spotify link
extension String {
func getAlbumId() -> String? {
let url = self
let base = Constants.BASE_URL_NEW_ALBUM
let start = base.count
if url.contains(base) && url.count > start {
let startIndex = url.index(url.startIndex, offsetBy: start)
public override func prepareForDeletion() {
if let artist = artist {
let albums = artist.albums
if albums == nil || albums?.count == 1 {
managedObjectContext?.delete(artist)
}
}
}
@harrysummers
harrysummers / gist:4a1af1d488d2dd4928095b5ab803d9c1
Created May 15, 2018 21:46
Sliding Left Transition Animation
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
let toView = transitionContext.view(forKey: .to)!
let fromView = transitionContext.view(forKey: .from)!
let slideTransform = CGAffineTransform(translationX: toView.frame.width, y: 0)
toView.transform = slideTransform
let finalFrame = CGRect(x: -fromView.frame.width, y: 0, width: fromView.frame.width, height: fromView.frame.height)
import UIKit
import SpotifyLogin
class SettingsViewController: UIViewController {
var scrollView: UIScrollView = {
var scroll = UIScrollView()
scroll.translatesAutoresizingMaskIntoConstraints = false
scroll.bounces = true
scroll.isScrollEnabled = true
@harrysummers
harrysummers / gist:6bc5d52897feca8afd24271c5346051d
Created May 17, 2018 20:17
UICollectionView programmatically
lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: 140, height: 250)
layout.scrollDirection = .horizontal
let collection = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
collection.translatesAutoresizingMaskIntoConstraints = false
collection.register(GifCollectionViewCell.self, forCellWithReuseIdentifier: cellId)
collection.backgroundColor = UIColor.CustomColors.spotifyDark
collection.bounces = true
collection.alwaysBounceHorizontal = true