Saturday 15 September 2012

swift - How to retrieve meta information from IOS media library -



swift - How to retrieve meta information from IOS media library -

i utilize code add together of info media object:

for song in songs { var media = media(artist: song.valueforproperty(mpmediaitempropertyartist) string, album: song.valueforproperty(mpmediaitempropertyalbumtitle) string, song: song.valueforproperty(mpmediaitempropertytitle) string, genre: song.valueforproperty(mpmediaitempropertygenre) string, duration: song.valueforproperty(mpmediaitempropertyplaybackduration) int, releasedate: song.valueforproperty(mpmediaitempropertyreleasedate) nsdate, artwork: song.valueforproperty(mpmediaitempropertyartwork) uiimageview, url: song.valueforproperty(mpmediaitempropertyasseturl) nsurl) medialist.append(media) }

this init media class:

init(artist: string, album: string, song: string, genre: string, duration: int, releasedate: nsdate, artwork: uiimageview, url: nsurl) { ............ }

but app crashes before adding object medialist. log:

libswiftcore.dylib`swift_dynamiccastobjcclassunconditional: 0x328df4: force {r4, r7, lr} 0x328df6: mov r4, r0 0x328df8: mov r2, r1 0x328dfa: add together r7, sp, #0x4 0x328dfc: cmp r4, #0x0 0x328dfe: beq 0x328e1a ; swift_dynamiccastobjcclassunconditional + 38 0x328e00: movw r0, #0x95dc 0x328e04: movt r0, #0x1 0x328e08: add together r0, pc 0x328e0a: ldr r1, [r0] 0x328e0c: mov r0, r4 0x328e0e: blx 0x335d94 ; symbol stub for: objc_msgsend 0x328e12: tst.w r0, #0xff 0x328e16: bne 0x328e1c ; swift_dynamiccastobjcclassunconditional + 40 0x328e18: trap 0x328e1a: movs r4, #0x0 0x328e1c: mov r0, r4 0x328e1e: pop {r4, r7, pc}

looks values empty used optional chaining:

if allow artist = song.valueforproperty(mpmediaitempropertyartist) as? string { } if allow album = song.valueforproperty(mpmediaitempropertyalbumtitle) as? string { } if allow song = song.valueforproperty(mpmediaitempropertytitle) as? string { } if allow gen = song.valueforproperty(mpmediaitempropertygenre) as? string { } if allow duration = song.valueforproperty(mpmediaitempropertyplaybackduration) as? int { } if allow date = song.valueforproperty(mpmediaitempropertyreleasedate) as? nsdate { } if allow img = song.valueforproperty(mpmediaitempropertyartwork) as? uiimageview { } if allow url = song.valueforproperty(mpmediaitempropertyasseturl) as? nsurl { }

ios swift

No comments:

Post a Comment