Skip to content

Instantly share code, notes, and snippets.

View myawesomehub's full-sized avatar
💛
Exploring

Mohammad Yasir myawesomehub

💛
Exploring
View GitHub Profile
```
import Foundation
struct mySortedArray<T: Comparable> {
// We are Creating an Array and intialise it
var array = [T]()
init(array: [T]) {
self.array = array.sorted()
}
@myawesomehub
myawesomehub / VoiceViewModel.swift
Created February 13, 2021 15:12
This Snippet of Code Includes the Start Recording and Stop Feature
import Foundation
import AVFoundation
class VoiceViewModel : NSObject , ObservableObject , AVAudioPlayerDelegate {
var audioRecorder : AVAudioRecorder!
var audioPlayer : AVAudioPlayer!
@Published var isRecording : Bool = false
@myawesomehub
myawesomehub / FetchAllRecording.swift
Created February 13, 2021 15:44
This Function Will Fetch the All Recordings from system to Array
func fetchAllRecording(){
let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let directoryContents = try! FileManager.default.contentsOfDirectory(at: path, includingPropertiesForKeys: nil)
for i in directoryContents {
recordingsList.append(Recording(fileURL : i, createdAt:getFileDate(for: i), isPlaying: false))
}
recordingsList.sort(by: { $0.createdAt.compare($1.createdAt) == .orderedDescending})
@myawesomehub
myawesomehub / StartPlaying.swift
Last active January 14, 2023 08:12
This Function will Play the Audio
func startPlaying(url : URL) {
let playSession = AVAudioSession.sharedInstance()
do {
try playSession.overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
} catch {
print("Playing failed in Device")
}
func deleteRecording(url : URL){
do {
try FileManager.default.removeItem(at : url)
} catch {
print("Can't delete")
}
for i in 0..<recordingsList.count {
@myawesomehub
myawesomehub / ContentView.swift
Last active February 14, 2021 08:32
This is main view of our app
struct ContentView: View {
@ObservedObject var vm = VoiceViewModel()
@State private var showingList = false
@State private var showingAlert = false
var body: some View {
ZStack{
@myawesomehub
myawesomehub / ListOfRecordings.swift
Created February 14, 2021 08:33
This is the List of Recordings
import SwiftUI
struct recordingListView: View {
@ObservedObject var vm = VoiceViewModel()
var body: some View {
NavigationView {
VStack {
ScrollView(showsIndicators: false){
@myawesomehub
myawesomehub / structLook.swift
Created February 20, 2021 05:14
How structures looks in swift programming
struct Book {
// Properties
// Methods
}
@myawesomehub
myawesomehub / instance.swift
Created February 20, 2021 05:21
Creating an instance of book structure
struct Book {
var title : String
var pages : Int
var chapters : Int
}
var book = Book(title: "The Swift Book", pages: 1030, chapters: 12)
print(book.pages)
import UIKit
enum Dice {
case one
case two
case three
case four
case five
case six
}