簡體   English   中英

初始化器類型無法構造,因為它沒有可訪問的初始化器

[英]Initializers Type Cannot be constructed because it has no accessible initializer

我在標題中提到了上面的問題,此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))
  }
}

1-)在左側面板上選擇項目根目錄

2-)在常規->部署信息窗口中,您可以設置目標。 在此處輸入圖片說明

兄弟,您已經更新了Xcode,並將代碼與以前的IOS版本一起使用。 您應該在8.2中搜索如何初始化這些變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM