小编thi*_*ift的帖子

Swift中的struct数组

元素的迭代产生错误

找不到会员'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 swift

6
推荐指数
1
解决办法
1万
查看次数

数组初始化之谜,以重复值作为序列,Swift

尝试传递生成的序列(可能是更复杂的 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”的正确方法是什么。或者我不应该为此烦恼并让数组成为一个变量,然后再填充它?

谢谢。

arrays initialization sequence swift

2
推荐指数
1
解决办法
1636
查看次数

NSLocalNotification的重复.驳回.合适的方式

我想在上午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社区的问题,我没有找到解雇它们的正确方法.

我认为:

  • 应用程序已终止,它们已安排并独立于应用程序执行操作.反复运行应用程序将创建更多通知.
  • 通知没有被正确解雇,并且即使在第二天也会返回昨天的消息.

帮助:

  1. 什么是解雇他们或检查他们是否已被解雇的正确方法(确保他们不重复
  2. 我是否每天都会循环并创建所有年份的通知,或者每次运行应用程序时为明天创建一个新通知

我错过了什么?代码欢迎.谢谢!

notifications ios swift

0
推荐指数
1
解决办法
180
查看次数

标签 统计

swift ×3

arrays ×1

initialization ×1

ios ×1

notifications ×1

sequence ×1

struct ×1