cowbell / cordova-plugin-geofence

Geofencing plugin for cordova
Apache License 2.0
264 stars 318 forks source link

Number of swift errors after adding plugin & following install instructions #228

Closed Quixotical closed 7 years ago

Quixotical commented 7 years ago

Note:: I have tried going through other issues people posted and applying the fixes others have suggested including going through SwiftyJSON, SwiftyData, and GeoFence classes & replacing all the errors with code supplied like it https://github.com/cowbell/cordova-plugin-geofence/issues/215 but there were errors which I could not resolve using the code referenced in that issue.

I added the plugin following the directions on the repo Creating Ionic 2 application:

1.) cordova plugin add cordova-plugin-geofence 2.) add to config.xml file 3.)

Since iOS 10 it's mandatory to add a NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription entries in the info.plist. verified that these were added to my plist.

Expectation: I build the app and it compiles successfully. Result: Failure due to swift needing upgrade with error message:

“Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

4.) Go into xCode & find edit > convert > To Current Swift Syntax 5.) Attempt to build project

Expectation: Builds Successfully Result: Build failure because of 48 errors in the newly converted swift code

/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:350:48: error: expected expression in list of expressions return JSONIndex(dictionaryIndex: <#T##Dictionary corresponding to your index##Dictionary<<#Key: Hashable#>, Any>#>.index(after: self.dictionaryIndex!)) ^ /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:350:103: error: editor placeholder in source file return JSONIndex(dictionaryIndex: <#T##Dictionary corresponding to your index##Dictionary<<#Key: Hashable#>, Any>#>.index(after: self.dictionaryIndex!)) ^ /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:350:126: error: expected expression after operator return JSONIndex(dictionaryIndex: <#T##Dictionary corresponding to your index##Dictionary<<#Key: Hashable#>, Any>#>.index(after: self.dictionaryIndex!)) ^ /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:233:58: warning: 'Indexable' is deprecated: it will be removed in Swift 4.0. Please use 'Collection' instead extension JSON : Swift.Collection, Swift.Sequence, Swift.Indexable { ^ /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:806:1: error: inheritance from non-protocol type 'Bool' extension JSON: Swift.Bool { ^ /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:417:40: error: use of undeclared type 'DictionaryGenerator' fileprivate var dictionayGenerate: DictionaryGenerator<String, AnyObject>? ^~~~~~~ /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:233:1: error: type 'JSON' does not conform to protocol '_IndexableBase' extension JSON : Swift.Collection, Swift.Sequence, Swift.Indexable { ^ Swift._IndexableBase:110:17: note: protocol requires function 'index(after:)' with type '(JSON.Index) -> JSON.Index'; do you want to add a stub? public func index(after i: Self.Index) -> Self.Index ^ Swift._Indexable:37:17: note: candidate has non-matching type ' (Self.Index, offsetBy: Self.IndexDistance) -> Self.Index' [with Element = JSONGenerator.Element, SubSequence = Slice] public func index( i: Self.Index, offsetBy n: Self .IndexDistance) -> Self.Index ^ Swift._Indexable:79:17: note: candidate has non-matching type ' (Self.Index, offsetBy: Self.IndexDistance, limitedBy: Self.Index) -> Self.Index?' [with Element = JSONGenerator.Element, SubSequence = Slice] public func index( i: Self.Index, offsetBy n: Self.IndexDistance, limitedBy limit: Self.Index) -> Self.Index? ^ Swift.Collection:22:17: note: candidate has non-matching type ' (of: Self.Iterator.Element) -> Self.Index?' [with _Element = JSONGenerator.Element, SubSequence = Slice] public func index(of element: Self.Iterator.Element) -> Self.Index? ^ Swift.Collection:24:17: note: candidate throws, but protocol does not allow it public func index(where predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Self.Index? ^ /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:968:65: warning: left side of nil coalescing operator '??' has non-optional type 'AnyObject', so the right side is never used self.object = newValue?.absoluteString as AnyObject ?? NSNull()



/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:116:59: error: 'jsonObject' produces 'Any', not the expected contextual result type 'AnyObject'
            let object: AnyObject = try JSONSerialization.jsonObject(with: data, options: opt)
                                                          ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:145:14: error: cannot invoke 'JSON.init' with an argument list of type '([AnyObject])'
        self.init(jsonArray.map { $0.object })
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:145:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(jsonArray.map { $0.object })
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:160:14: error: cannot invoke 'JSON.init' with an argument list of type '([String : AnyObject])'
        self.init(dictionary)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:160:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(dictionary)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:434:47: error: '++' is unavailable: it has been removed in Swift 3
                return (String(self.arrayIndex++), JSON(o))
                                              ^~
Swift.++:3:21: note: '++' has been explicitly marked unavailable here
postfix public func ++(x: inout Int) -> Int
                    ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:598:14: error: cannot invoke 'JSON.init' with an argument list of type '(StringLiteralType)'
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:598:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:602:14: error: cannot invoke 'JSON.init' with an argument list of type '(StringLiteralType)'
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:602:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:606:14: error: cannot invoke 'JSON.init' with an argument list of type '(StringLiteralType)'
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:606:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:613:14: error: cannot invoke 'JSON.init' with an argument list of type '(IntegerLiteralType)'
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:613:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:620:14: error: cannot invoke 'JSON.init' with an argument list of type '(BooleanLiteralType)'
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:620:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:627:14: error: cannot invoke 'JSON.init' with an argument list of type '(FloatLiteralType)'
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:627:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:634:14: error: cannot invoke 'JSON.init' with an argument list of type '([String : AnyObject])'
        self.init(elements.reduce([String : AnyObject]()){(dictionary: [String : AnyObject], element:(String, AnyObject)) -> [String : AnyObject] in
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:634:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(elements.reduce([String : AnyObject]()){(dictionary: [String : AnyObject], element:(String, AnyObject)) -> [String : AnyObject] in
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:645:14: error: cannot invoke 'JSON.init' with an argument list of type '([AnyObject])'
        self.init(elements)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:645:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists
: (AnyObject), ([JSON]), ([String : JSON])
        self.init(elements)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:680:62: error: default argument value of type 'String.Encoding' cannot be converted to type 'UInt'
    public func rawString(_ encoding: UInt = String.Encoding.utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted) -> String? {
                                             ~~~~~~~~~~~~~~~~^~~~
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:685:65: warning: conditional downcast from 'NSString?' to 'String' is a bridging conversion; did you mean to use 'as'?
                return NSString(data: data, encoding: encoding) as? String
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~ ~~~~~~
                                                                as        ?

** BUILD FAILED **

The following build commands failed:

    CompileSwift normal x86_64 /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/GeofencePlugin.swift
    CompileSwift normal x86_64 /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftData.swift
    CompileSwift normal x86_64 /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift
    CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(4 failures)

Error: Error code 65 for command: xcodebuild with args: -xcconfig,/platforms/ios/cordova/build-debug.xcconfig,-workspace,CatchABreak.xcworkspace,-scheme,CatchABreak,-configuration,Debug,-sdk,iphonesimulator,-destination,platform=iOS Simulator,name=iPhone 5s,build,CONFIGURATION_BUILD_DIR=/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/platforms/ios/build/sharedpch

I don't think I missed any steps in getting this set up, and I really have no idea how to fix all these issues with the swift code. Any help/guidance would be greatly appreciated
Quixotical commented 7 years ago

this issue has been resolved. Please view ticket https://github.com/cowbell/cordova-plugin-geofence/issues/222 for resolution