我正在使用 swift 1 参加在线课程。这些代码在 1 处没问题,但在 2 处显示运行时错误。
MusicLibrary.swift
let library = [
[
"title": "Rise and Shine",
"description": "Get your morning going by singing along to these classic tracks as you hit the shower bright and early!",
"icon": "coffee.pdf",
"largeIcon": "coffee_large.pdf",
"backgroundColor": ["red": 255, "green": 204, "blue": 51, "alpha": 1.0],
"artists": ["American Authors", "Vacationer", "Matt and Kim", "MGMT", "Echosmith", "Tokyo Police Club", "La Femme"]
]
播放列表.swift
init(index: Int) {
let musicLibrary = MusicLibrary().library
let playlistDictionary = musicLibrary[index]
title = playlistDictionary["title"] as String!
description = playlistDictionary["description"] as String!
let iconName = playlistDictionary["icon"] as String!
icon = UIImage(named: iconName!)
let largeIconName = playlistDictionary["largeIcon"] as String!
largeIcon = UIImage(named: largeIconName!)
artists += playlistDictionary["artist"] as [String]
}