Skip to content

Instantly share code, notes, and snippets.

View alexpaul's full-sized avatar
:octocat:

Alex Paul alexpaul

:octocat:
View GitHub Profile
@alexpaul
alexpaul / FetchAPI-Swift-Podcasts.js
Created June 12, 2018 14:04
Javascript Fetch API usage to make a GET request for Swift Podcasts
// fetch api making a GET request for Podcasts from Apple Search API
// Asynchronous request so we need to use Promises to listen for completions of task
// filter() is used to get only Swift Podcast related to "Technology" included as part of the genres array
fetch('https://itunes.apple.com/search?media=podcast&limit=200&term=swift')
.then((response) => response.json())
.then((jsonData) => {
const resultCount = jsonData['resultCount']
const results = jsonData['results']
const filteredPodcasts = results.filter((podcast) => (podcast.genres.includes('Technology')))
@alexpaul
alexpaul / App.js
Last active March 6, 2022 20:59
Embedding a screen within a Navigation stack using react-navigation package
import React from 'react';
// import third party libraries
import { createStackNavigator } from 'react-navigation'
// import screens
import MainScreen from './screens/MainScreen'
import DetailScreen from './screens/DetailScreen'
const RootStack = createStackNavigator({
@alexpaul
alexpaul / NavigationHeader.js
Created June 19, 2018 01:55
Setting the Navigation Header values using react-navigation
static navigationOptions = ({ navigation }) => ({
title: 'Home',
headerTitleStyle: {textAlign: 'center', alignSelf: 'center'},
headerStyle: {backgroundColor: 'powderblue'},
})
@alexpaul
alexpaul / ConditionalImageLoading.js
Created June 19, 2018 03:03
Placeholder image in preparation for asynchronous image loading in react-native
<Image
source={
this.state.isLoaded
?
{uri:this.state.imageURL}
:
require('../assets/placeholder-image.png')
}
style={styles.detailImage}
/>
@alexpaul
alexpaul / SetupTabIcons.js
Created June 21, 2018 16:15
Setting up tab bar icons using react-navigation and react-native-vector-icons
const TabStack = createBottomTabNavigator(
{
Search: HomeNavStack,
Favorites: FavoritesNavStack,
},
{
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
let iconName;
@alexpaul
alexpaul / CustomCallout.swift
Created June 30, 2018 11:13
Setting up a custom callout on the detailCalloutAccessoryView in a MapView
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "PlaceAnnotationView") as? MKMarkerAnnotationView
if annotationView == nil {
annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "PlaceAnnotationView")
annotationView?.canShowCallout = true
} else {
annotationView?.annotation = annotation
@alexpaul
alexpaul / ManagingKeyboard.swift
Last active January 30, 2019 00:03
Setting up keyboard notifications and responding to their actions
//
// ViewController.swift
// KeyboardHandling
//
// Created by Alex Paul on 1/29/19.
// Copyright © 2019 Alex Paul. All rights reserved.
//
import UIKit
@alexpaul
alexpaul / AttributedStringExample.swift
Created August 7, 2018 19:10
NSAttributedString example that illustrates adding attributes to a String and setting the attributedText property on a UILabel
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var nameLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let text = "stockholm, sweden"
@alexpaul
alexpaul / ApplicationInfo.swift
Last active June 10, 2020 20:58
Get the version and build number for your app. This is especially useful to track version / builds on the AppStore / TestFlight.
import Foundation
class ApplicationInfo {
class func getVersionBuildNumber() -> String {
guard let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString"),
let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion")
else {
fatalError("no version info")
}
return "\(version) (\(build))"
@alexpaul
alexpaul / VoiceOverLanguages.swift
Created September 22, 2018 22:04
List of Voice Over Languages
// print(AVSpeechSynthesisVoice.speechVoices())
[[AVSpeechSynthesisVoice 0x283654fe0] Language: ar-SA, Name: Maged, Quality: Default [com.apple.ttsbundle.Maged-compact], [AVSpeechSynthesisVoice 0x283655560] Language: cs-CZ, Name: Zuzana, Quality: Default [com.apple.ttsbundle.Zuzana-compact], [AVSpeechSynthesisVoice 0x2836552e0] Language: da-DK, Name: Sara, Quality: Default [com.apple.ttsbundle.Sara-compact], [AVSpeechSynthesisVoice 0x283654c60] Language: de-DE, Name: Anna, Quality: Default [com.apple.ttsbundle.Anna-compact], [AVSpeechSynthesisVoice 0x2836550a0] Language: el-GR, Name: Melina, Quality: Default [com.apple.ttsbundle.Melina-compact], [AVSpeechSynthesisVoice 0x283654ea0] Language: en-AU, Name: Karen, Quality: Default [com.apple.ttsbundle.Karen-compact], [AVSpeechSynthesisVoice 0x283654d20] Language: en-GB, Name: Daniel, Quality: Default [com.apple.ttsbundle.Daniel-compact], [AVSpeechSynthesisVoice 0x283655120] Language: en-IE, Name: Moira, Quality: Default [com.apple.ttsbundle.Moira-compact], [AVS