元素的迭代产生错误
找不到会员'convertFromStringInterpolationSegment'
println("\(contacts[count].name)")",直接列表项打印正常.
我错过了什么?
struct Person {
var name: String
var surname: String
var phone: String
var isCustomer: Bool
init(name: String, surname: String, phone: String, isCustomer: Bool)
{
self.name = name
self.surname = surname
self.phone = phone
self.isCustomer = isCustomer
}
}
var contacts: [Person] = []
var person1: Person = Person(name: "Jack", surname: "Johnson", phone: "7827493", isCustomer: false)
contacts.append(person1)
var count: Int = 0
for count in contacts {
println("\(contacts[count].name)") // here's where I get an error
} …Run Code Online (Sandbox Code Playgroud) 尝试传递生成的序列(可能是更复杂的 struct 或 func 值),例如在数组初始化期间生成一些键字符串。
这是一个数组初始化字符串:
let MyArray: Array<Int> = Array<Int>(count: 100, repeatedValue:(for i in 0...99))
// it does not work, I am doing it wrong :(
// instead of (for i in 0...99) could be anything, a key sequence generator
Run Code Online (Sandbox Code Playgroud)
以下是文档中的内容:
/// Construct a Array of `count` elements, each initialized to
/// `repeatedValue`.
init(count: Int, repeatedValue: T)
Run Code Online (Sandbox Code Playgroud)
用生成或排序的值替换“T”的正确方法是什么。或者我不应该为此烦恼并让数组成为一个变量,然后再填充它?
谢谢。
我想在上午10点创建每日通知,每天都有不同的内容.
func createNotification() {
let dateComp:NSDateComponents = NSDateComponents()
dateComp.hour = 10; // supposed to run each day at 10AM
var myCalendar:NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
var date:NSDate = myCalendar.dateFromComponents(dateComp)!
let localNotification = UILocalNotification()
localNotification.fireDate = date
localNotification.alertBody = getContentStringForNotification() // Method returns different string for each date
localNotification.repeatInterval = .Day // Repeats every day
localNotification.timeZone = NSTimeZone.defaultTimeZone()
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
Run Code Online (Sandbox Code Playgroud)
它重复通知.他们不断重复并返回昨天的通知.我搜索了Stack社区的问题,我没有找到解雇它们的正确方法.
我认为:
帮助:
我错过了什么?代码欢迎.谢谢!