Posts

Post marked as solved
2 Replies
44k Views
Export Compliance Information. Does your app use encryption? Select Yes even if your app only uses the standard encryption within Apple’s operating system. 1. My app is making a call to HTTPS only. Should I select Yes or No? 2. Should I send report to the US government if my app available in Germany only (doesn't available in the USA)?
Posted
by Iraklii.
Last updated
.
Post not yet marked as solved
1 Replies
530 Views
I would like to use NSMergeByPropertyObjectTrumpMergePolicy but ignore field during the merge. I'm loading feeds/posts from the backend. For example: My object has fields id: Int64 (Contraint) seen: Bool (Default value is false) I change seen value to true and make save context. After that I'm loading same feeds/posts from the backend, happens merge and seen fields changes true value to false. As I understand there is only one way to resolve this problem, implement custom merge policy. To make this I need to implement subclass of NSMergePolicy. But I didn't find any samples how to implement custom merge policy.
Posted
by Iraklii.
Last updated
.
Post not yet marked as solved
1 Replies
461 Views
let bassNotes: [MIDINotes] = [ &#9;&#9;.g3, .rest, .g2, .rest, &#9;&#9;.c3, .g3, .c4, .rest, &#9;&#9;.b4, .rest, .as4, .rest, &#9;&#9;.f2, .rest, .f3, .e3, &#9;&#9;.d3, .rest, .g2, .rest, &#9;&#9;.c4, .rest, .rest, .rest, &#9;&#9;.a3, .rest, .fs3, .rest, &#9;&#9;.f3, .d3, .c4, .a3 ] let trebleNotes: [MIDINotes] = [ &#9;&#9;.rest, .b3, .c4, .d4, &#9;&#9;.e4, .rest, .rest, .d4, &#9;&#9;.e4, .a4, .g4, .e4, &#9;&#9;.d4, .c4, .a3, .rest, &#9;&#9;.rest, .c4, .e4, .f4, &#9;&#9;.g4, .rest, .rest, .a4, &#9;&#9;.g4, .e4, .c4, .e4, &#9;&#9;.d4, .rest, .rest, .rest ] func performance(owner: Assessable) { &#9;&#9;let numberOfBeats = 32 &#9;&#9;let duration = 16.0&#9; &#9;&#9; &#9;&#9;var bass = Track(instrument: .bassGuitar, length: numberOfBeats) &#9;&#9;var piano = Track(instrument: .piano, length: numberOfBeats) &#9;&#9;let tracks = [bass, piano] &#9;&#9; &#9;&#9;bass.notes =&#9;bassNotes &#9;&#9;piano.notes = trebleNotes &#9;&#9; &#9;&#9;let interval = duration / Double(numberOfBeats) &#9;&#9;var index = 0 &#9;&#9;Timer.scheduledTimer(withTimeInterval: interval, repeats: true, block: { timer in &#9;&#9;&#9;&#9;playInstrument(piano.instrument, note: piano.note(for: index)) &#9;&#9;&#9;&#9;playInstrument(bass.instrument, note: bass.note(for: index)) &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;if index + 1 < numberOfBeats { &#9;&#9;&#9;&#9;&#9;&#9;index = index + 1 &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;else { &#9;&#9;&#9;&#9;&#9;&#9;index = 0 &#9;&#9;&#9;&#9;&#9;&#9;owner.endPerformance() &#9;&#9;&#9;&#9;} &#9;&#9;}) &#9;&#9;owner.endPerformance() } public struct Track : TrackProtocol { &#9;&#9; &#9;&#9;public var instrument: Instrument.Kind &#9;&#9;public var length: Int &#9;&#9; &#9;&#9;var notes: [MIDINotes]? = nil &#9;&#9; &#9;&#9;public func note(for frame: Int) -> MIDINotes { &#9;&#9;&#9;&#9;guard let n = notes, frame < n.count else { &#9;&#9;&#9;&#9;&#9;&#9;return .rest &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;return n[frame] &#9;&#9;} } Cool chapters and the last one especially! Thank you!!! :)
Posted
by Iraklii.
Last updated
.
Post not yet marked as solved
0 Replies
381 Views
We can use second timer for bass chords but it won't be sync with first. In any case I commented second timer and added bassToneOutput to the first timer to sync it. func performance(owner: Assessable) { &#9;&#9;let toneOutput = ToneOutput() &#9;&#9;let bassToneOutput = ToneOutput() &#9;&#9;let qPitches:[Pitch] = [.e3, .e3, .f3, .g3, .g3, .f3, .e3, .d3, .c3, .c3, .d3, .e3, .e3, .d3] &#9;&#9;let hPitches:[Pitch] = [.d3] &#9;&#9;let notes: [Note] = qPitches.map{Note.quarter($0)} + hPitches.map{Note.half($0)} &#9;&#9;var pitches = [Pitch]() &#9;&#9;for note in notes { &#9;&#9;&#9;&#9;pitches.append(contentsOf: note.subdivide()) &#9;&#9;} &#9;&#9;var index = 0 &#9;&#9;let interval = TimeInterval(Note.shortestSupportedNoteLength * 0.5) &#9;&#9;Timer.scheduledTimer(withTimeInterval: interval, repeats: true) { timer in &#9;&#9;&#9;&#9;guard index < pitches.count else { &#9;&#9;&#9;&#9;&#9;&#9;toneOutput.stopTones() &#9;&#9;&#9;&#9;&#9;&#9;bassToneOutput.stopTones() &#9;&#9;&#9;&#9;&#9;&#9;timer.invalidate() &#9;&#9;&#9;&#9;&#9;&#9;owner.endPerformance() &#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;toneOutput.play(tone: Tone(pitch: pitches[index].frequency, volume: 0.3)) &#9;&#9;&#9;&#9;bassToneOutput.play(tone: Tone(pitch: pitches[index].bassFrequency, volume: 0.3)) &#9;&#9;&#9;&#9;index += 1 &#9;&#9;} &#9;&#9;&#9;&#9;// Second timer but it won’t with the first timer. //&#9;&#9;&#9;Timer.scheduledTimer(withTimeInterval: interval, repeats: true) { timer in //&#9;&#9;&#9;&#9;&#9;guard index < pitches.count else { //&#9;&#9;&#9;&#9;&#9;&#9;&#9;bassToneOutput.stopTones() //&#9;&#9;&#9;&#9;&#9;&#9;&#9;timer.invalidate() //&#9;&#9;&#9;&#9;&#9;&#9;&#9;owner.endPerformance() //&#9;&#9;&#9;&#9;&#9;&#9;&#9;return //&#9;&#9;&#9;&#9;&#9;} //&#9;&#9;&#9;&#9;&#9; //&#9;&#9;&#9;&#9;&#9;bassToneOutput.play(tone: Tone(pitch: pitches[index].bassFrequency, volume: 0.3)) //&#9;&#9;&#9;&#9;&#9;//index += 1 //&#9;&#9;&#9;} &#9;&#9; &#9;&#9;owner.endPerformance() } Add new property to Pitch public var bassFrequency: Double { &#9;&#9;&#9;&#9;return self.rawValue/2.0 }
Posted
by Iraklii.
Last updated
.
Post not yet marked as solved
0 Replies
479 Views
Advice from the Lizard: let notes: [Note] = [Note.quarter(.a4), .quarter(.b4), .quarter(.c4)] Performance at Swan Hall: func performance(owner: Assessable) { &#9;&#9;let toneOutput = ToneOutput() &#9;&#9;let qPitches:[Pitch] = [.e3, .e3, .f3, .g3, .g3, .f3, .e3, .d3, .c3, .c3, .d3, .e3, .e3, .d3] &#9;&#9;let hPitches:[Pitch] = [.d3] &#9;&#9;let notes: [Note] = qPitches.map{Note.quarter($0)} + hPitches.map{Note.half($0)} &#9;&#9;var pitches = [Pitch]() &#9;&#9;for note in notes { &#9;&#9;&#9;&#9;pitches.append(contentsOf: note.subdivide()) &#9;&#9;} &#9;&#9;var index = 0 &#9;&#9; &#9;&#9;let interval = TimeInterval(Note.shortestSupportedNoteLength * 0.5) &#9;&#9;Timer.scheduledTimer(withTimeInterval: interval, repeats: true) { timer in &#9;&#9;&#9;&#9;guard index < pitches.count else { &#9;&#9;&#9;&#9;&#9;&#9;toneOutput.stopTones() &#9;&#9;&#9;&#9;&#9;&#9;timer.invalidate() &#9;&#9;&#9;&#9;&#9;&#9;owner.endPerformance() &#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;toneOutput.play(tone: Tone(pitch: pitches[index].frequency, volume: 0.3)) &#9;&#9;&#9;&#9;index += 1 &#9;&#9;} &#9;&#9;owner.endPerformance() } Music.swift public enum Note : NoteProtocol { &#9;&#9;case quarter(Pitch) &#9;&#9;case half(Pitch) &#9;&#9; &#9;&#9;/// Play this Note through a ToneOutput &#9;&#9;public var tone: Tone { &#9;&#9;&#9;&#9;switch self { &#9;&#9;&#9;&#9;case .quarter(let pitch): &#9;&#9;&#9;&#9;&#9;&#9;return Tone(pitch: pitch.frequency, volume: 0.3) &#9;&#9;&#9;&#9;&#9;&#9;case .half(let pitch): &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;return Tone(pitch: pitch.frequency, volume: 0.3) &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; &#9;&#9;/// The duration of this Note as a multiple of quarter notes, e.g., a half note would equal 2.0, an eight note &#9;&#9;public var length: Float { &#9;&#9;&#9;&#9;switch self { &#9;&#9;&#9;&#9;case .quarter(_): &#9;&#9;&#9;&#9;&#9;&#9;return 1.0 &#9;&#9;&#9;&#9;case .half(_): &#9;&#9;&#9;&#9;&#9;&#9;return 2.0 &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; &#9;&#9;/// Length of the smallest Note supported &#9;&#9;public static var shortestSupportedNoteLength: Float { &#9;&#9;&#9;&#9;return Note.quarter(.a4).length &#9;&#9;} &#9;&#9; &#9;&#9;/// Subdivide into a series pitches, according to the shortest supported note &#9;&#9;public func subdivide() -> [Pitch] { &#9;&#9;&#9;&#9;switch self { &#9;&#9;&#9;&#9;case .quarter(let pitch): &#9;&#9;&#9;&#9;&#9;&#9;return [pitch] &#9;&#9;&#9;&#9;case .half(let pitch): &#9;&#9;&#9;&#9;&#9;&#9;return [pitch, pitch] &#9;&#9;&#9;&#9;} &#9;&#9;} } Nice quests but Ode to Joy it's headshot :D
Posted
by Iraklii.
Last updated
.
Post not yet marked as solved
0 Replies
450 Views
Hope this solution is clear. C Major - is c,d,e,f,g,a,b,c' F Major - is f,g,a,bb,c',d',e',f' ' - means new octave bb - b flat enum CMajor: Double, CaseIterable {     case c = 261.63     case d = 293.66     case e = 329.63     case f = 349.23     case g = 392.00     case a = 440.00     case b = 493.88     var fMajorFrequency: Double {         switch self {         case .b:             return 466.16         default:             return self.rawValue * 2         }     }     static var fMajorFrequencies: [Double] {          [CMajor.f.rawValue, CMajor.g.rawValue, CMajor.a.rawValue, CMajor.b.fMajorFrequency, CMajor.c.fMajorFrequency, CMajor.d.fMajorFrequency, CMajor.e.fMajorFrequency, CMajor.f.fMajorFrequency ]     }  } func performance(owner: Assessable) {     let toneOutput = ToneOutput()     var cMajorFrequencies = CMajor.allCases.map{$0.rawValue}      cMajorFrequencies.append(CMajor.c.rawValue*2)     let cTones = cMajorFrequencies.map( { Tone(pitch: $0, volume: 0.3) })     let fTones = CMajor.fMajorFrequencies.map( { Tone(pitch: $0, volume: 0.3) })     var toneIndex = 0     let tones = fTones     Timer.scheduledTimer(withTimeInterval: 0.4, repeats: true) { timer in         guard toneIndex < tones.count else {             toneOutput.stopTones()             timer.invalidate()             owner.endPerformance()             return         }         toneOutput.play(tone: tones[toneIndex])         toneIndex += 1     }     owner.endPerformance() }
Posted
by Iraklii.
Last updated
.