Initializers Type无法构造,因为它没有可访问的初始值设定项

时间:2015-05-27 14:29:59

标签: swift

我遇到了上述问题,如标题中所提到的,这个porgram是以IOS 8.2为目标 但是当我在我的Xcode中使用它时,它会显示错误,因为目标是8.0 请提前感谢:)

我的代码是下面给出的,我需要它用于目标8.0

import UIKit
import MapKit
import CoreLocation

let kGeotificationLatitudeKey = "latitude"
let kGeotificationLongitudeKey = "longitude"
let kGeotificationRadiusKey = "radius"
let kGeotificationIdentifierKey = "identifier"
let kGeotificationNoteKey = "note"
let kGeotificationEventTypeKey = "eventType"

enum EventType: Int {
 case OnEntry = 0
 case OnExit = 1
}

class Geotification: NSObject, NSCoding, MKAnnotation {
 var coordinate: CLLocationCoordinate2D
 var radius: CLLocationDistance
 var identifier: String
 var note: String
 var eventType: EventType

 var title: String {
  if note.isEmpty {
   return "No Note"
  }
  return note
 }

 var subtitle: String {
  var eventTypeString = eventType == .OnEntry ? "On Entry" : "On Exit"
  return "Radius: \(radius)m - \(eventTypeString)"
 }

 init(coordinate: CLLocationCoordinate2D, radius: CLLocationDistance,             identifier: String, note: String, eventType: EventType) {
  self.coordinate = coordinate
  self.radius = radius
  self.identifier = identifier
  self.note = note
  self.eventType = eventType
 }

 // MARK: NSCoding

 required init(coder decoder: NSCoder) {
  let latitude = decoder.decodeDoubleForKey(kGeotificationLatitudeKey)
  let longitude = decoder.decodeDoubleForKey(kGeotificationLongitudeKey)
  coordinate = CLLocationCoordinate2D(latitude: latitude, longitude:       longitude)
  radius = decoder.decodeDoubleForKey(kGeotificationRadiusKey)
  identifier = decoder.decodeObjectForKey(kGeotificationIdentifierKey) as  String
  note = decoder.decodeObjectForKey(kGeotificationNoteKey) as String
  eventType =         EventType(decoder.decodeIntegerForKey(kGeotificationEventTypeKey))

 }

 func encodeWithCoder(coder: NSCoder) {
  coder.encodeDouble(coordinate.latitude, forKey: kGeotificationLatitudeKey)
  coder.encodeDouble(coordinate.longitude, forKey: kGeotificationLongitudeKey)
    coder.encodeDouble(radius, forKey: kGeotificationRadiusKey)
    coder.encodeObject(identifier, forKey: kGeotificationIdentifierKey)
    coder.encodeObject(note, forKey: kGeotificationNoteKey)
    coder.encodeInt(Int32(eventType.rawValue, forKey:     kGeotificationEventTypeKey))
  }
}

2 个答案:

答案 0 :(得分:0)

1-)在左侧面板中选择项目根目录

2-)一般 - >部署信息窗口,您可以设置目标。enter image description here

答案 1 :(得分:0)

您已经更新了Xcode并使用了以前IOS版本的代码。你应该在8.2 ..

中搜索如何初始化这些变量