This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
import Foundation | |
struct mySortedArray<T: Comparable> { | |
// We are Creating an Array and intialise it | |
var array = [T]() | |
init(array: [T]) { | |
self.array = array.sorted() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import AVFoundation | |
class VoiceViewModel : NSObject , ObservableObject , AVAudioPlayerDelegate { | |
var audioRecorder : AVAudioRecorder! | |
var audioPlayer : AVAudioPlayer! | |
@Published var isRecording : Bool = false | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func deleteRecording(url : URL){ | |
do { | |
try FileManager.default.removeItem(at : url) | |
} catch { | |
print("Can't delete") | |
} | |
for i in 0..<recordingsList.count { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@ObservedObject var vm = VoiceViewModel() | |
@State private var showingList = false | |
@State private var showingAlert = false | |
var body: some View { | |
ZStack{ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct recordingListView: View { | |
@ObservedObject var vm = VoiceViewModel() | |
var body: some View { | |
NavigationView { | |
VStack { | |
ScrollView(showsIndicators: false){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Book { | |
// Properties | |
// Methods | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
enum Dice { | |
case one | |
case two | |
case three | |
case four | |
case five | |
case six | |
} |
OlderNewer