小编Mwc*_*Mac的帖子

Swift将unix时间转换为日期和时间

我目前的代码:

if  let var timeResult = (jsonResult["dt"] as? Double) {
    timeResult = NSDate().timeIntervalSince1970
    println(timeResult)
    println(NSDate())
}
Run Code Online (Sandbox Code Playgroud)

结果:

println(timeResult) = 1415639000.67457

println(NSDate())= 2014-11-10 17:03:20 +0000只是为了测试看看NSDate提供什么.

我希望第一个看起来像最后一个.dt = 1415637900的值.

另外,我如何调整时区?在iOS上运行.

time ios swift

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

从Coredata Swift中删除数据

在我的tableViewController中,我有以下内容.我试图删除一个项目工作.

var myData: Array<AnyObject> = []

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cellID: NSString = "Cell"
    var Cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellID) as UITableViewCell
    var data: NSManagedObject = myData[indexPath.row] as NSManagedObject
    Cell.textLabel?.text = data.valueForKeyPath("Name") as? String

    return Cell
}
Run Code Online (Sandbox Code Playgroud)

然后尝试删除我有.

override func tableView(tableView: (UITableView!), commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
        let cellID: NSString = "Cell"
        var Cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellID) as UITableViewCell
        var data: NSManagedObject = myData[indexPath.row] as NSManagedObject
        data.delete(0) …
Run Code Online (Sandbox Code Playgroud)

core-data swift

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

添加文本编辑器 / SwiftUi

我无法调整我创建的文本编辑器的外观。文本将有边距。\n我尝试自己做,但我搞砸了,我不能\t我希望它像图片一样。

\n

在此输入图像描述

\n
  VStack {\n            TextEditor(text: $inputText)\n                .background(Color.black)\n                .frame(height:geometry.size.height / 3, alignment: .center)\n                .cornerRadius(25)\n                .border(Color.yellow, width: 5)\n                .lineSpacing(10)\n                .autocapitalization(.words)\n                .disableAutocorrection(true)\n                .padding()  \n            }\n\n            Spacer().frame(height: geometry.size.height / 15)\n\n            VStack {\n                Button(action: {}, label: {\n                    Text("G\xc3\xb6nder")\n                        .frame(width: geometry.size.width / 3, height: 50)\n                        .padding(10)\n                        .font(Font.system(size: 30, weight: .medium, design: .serif))\n                        .foregroundColor(.white)\n                        .background(RoundedRectangle(cornerRadius: 30))\n                        .foregroundColor(.init(red: 45 / 255, green: 0 / 255, blue: 112 / 255))\n\n                })\n            }\n
Run Code Online (Sandbox Code Playgroud)\n

ios swift swiftui

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

Swift将十进制坐标转换为度,分,秒,方向

我该如何将其转换为快速?我最好的猜测是所有的int都变成了var.删除所有@那个领导".如果有的话可以指向一个好的来源,以了解事情如何转换,这将是伟大的.

- (NSString*)coordinateString {

int latSeconds = (int)(self.latitude * 3600);
int latDegrees = latSeconds / 3600;
latSeconds = ABS(latSeconds % 3600);
int latMinutes = latSeconds / 60;
latSeconds %= 60;

int longSeconds = (int)(self.longitude * 3600);
int longDegrees = longSeconds / 3600;
longSeconds = ABS(longSeconds % 3600);
int longMinutes = longSeconds / 60;
longSeconds %= 60;

NSString* result = [NSString stringWithFormat:@"%d°%d'%d\"%@ %d°%d'%d\"%@",
                    ABS(latDegrees),
                    latMinutes,
                    latSeconds,
                    latDegrees >= 0 ? @"N" : @"S",
                    ABS(longDegrees),
                    longMinutes,
                    longSeconds,
                    longDegrees >= 0 ? @"E" …
Run Code Online (Sandbox Code Playgroud)

gps swift xcode6

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

如何使用Swift iOS在Mapview中添加两个注释?

 let latitude:CLLocationDegrees = 76.0100
 let longitude:CLLocationDegrees =25.3620


 let location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)

 let latDelta:CLLocationDegrees = 1
 let lonDelta:CLLocationDegrees = 1
 let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)

 let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)

 mapView.setRegion(region, animated: true)

 let annotation:MKPointAnnotation = MKPointAnnotation()
    annotation.coordinate = location
    annotation.title = "Office ."
    annotation.subtitle = "My Office"

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {


    print("Locations = \(locations)")

    let userLocation: CLLocation = locations[0] as CLLocation

    //var latitude:CLLocationDegrees = userLocation.coordinate
    //var longitude:CLLocationDegrees = -121.934048
    //var location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)

    let latDelta:CLLocationDegrees …
Run Code Online (Sandbox Code Playgroud)

mkmapview ios swift

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

在展开可选值NSDefautlts时发现了nil的swift问题

致命错误的问题:在展开Optional值时意外发现nil.

let lastupdate = defaults.stringForKey("localdate")
self.lastUpdate.text = "Updated at " + last update! //issues when I use this line
self.lastUpdate.text = lastupdate // If use this line I have no issues.
Run Code Online (Sandbox Code Playgroud)

如果我预先填充数据,则有效.但我想允许零值.

null xcode swift xcode-6.2

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

标签 统计

swift ×6

ios ×3

core-data ×1

gps ×1

mkmapview ×1

null ×1

swiftui ×1

time ×1

xcode ×1

xcode-6.2 ×1

xcode6 ×1