Upgrade to Swift 4. iOS Charts won't build - ios

I'm using the Charts library from Github. The documentation indicates the Pod is updated to support XCode 9 and Swift 4 yet I'm getting errors.
I removed the pod by opening the podfile and removing that line. I then enter Pod Install into terminal, to remove it. I then reinstalled to make sure I have the most up to date branch.
The instruction is:
Add pod 'Charts' to your Podfile.
My error message is:
Cannot subsript a value of type [String: AnyObject] with an index of
type NSAttributedStringKey
The error occurs on the second and third line of this function:
var attrs = [String : AnyObject]()
attrs[NSFontAttributeName] = description.font
attrs[NSForegroundColorAttributeName] = description.textColor
ChartUtils.drawText(
context: context,
text: descriptionText,
point: position!,
align: description.textAlign,
attributes: attrs
)

I downloaded the new Swift 4 version and replaced the charts xcodeproj in my project, and it went like cream (Very smooth and easy) no 3.0.3 or pods (what are pods?)
The error in your question occurred when I upgraded to Swift 4 with the old Swift 3 charts source code. The error relates to type, and in my case mostly had a fix.
Excellent package well done Daniel

Related

Syntax errors in Lyft API for iOS - won't compile?

I am trying to use the Lyft API for iOS with Swift 4 and Xcode 9.3.
When I use the pod LyftSDK, the framework files do not compile per this issue, which I fixed (but it seemed bizarre that a major API would not compile in a production build). It's currently an open issue on the Lyft-iOS-SDK GitHub, #17. I'm also using the pod Lyft because I was unsure of which to use.
In my view controller, I've imported:
import Lyft
import LyftSDK
But then when I go to use let lyftButton = LyftButton() I get the compilation error Use of unresolved identifier 'LyftButton'.
How do I use this API with Swift? Do I need both pods for it to work? I'm following the documentation line for line and can't get it to work how it's supposed to. None of the other APIs and CocoaPods I'm using have this issue.
I solved this by doing the following:
In LyftSDK/Core/LyftButton.swift, change Line 47 from private var pressUpAction: ((Void) -> Void)? to private var pressUpAction: (() -> Void)?.
In LyftSDK/Core/LyftAPIURLEncoding.swift, replace Line 32 with:
var localVariable = urlComponents
urlComponents?.queryItems = (localVariable?.queryItems ?? []) + queryItems

NSAttributedStringKey.attachment versus NSAttachmentAttributeName

I'm having problems with NSAttributedStringKey.attachment versus NSAttachmentAttributeName. Here's the relevant code:
var key: Any?
if #available(iOS 11, *) {
key = NSAttributedStringKey.attachment
}
else {
key = NSAttachmentAttributeName
}
One of two things are happening. In the actual place where I'm trying to use this code (a Cococapod of my own design, with a deployment target of iOS 8 and now building with Xcode 9), I get an error:
Type 'NSAttributedStringKey' (aka 'NSString') has no member 'attachment'
Or, if I just make a new example project and set the deployment target at iOS 8, I get:
'NSAttachmentAttributeName' has been renamed to 'NSAttributedStringKey.attachment'
This is not the behavior I'd expect with #available. Thoughts?
This String vs struct difference is between Swift 3 (uses Strings such as NSAttachmentAttributeName) and Swift 4 (uses struct static attributes such as NSAttributedStringKey.attachment), not between iOS <11 and iOS >=11. For instance, you can use NSAttributedStringKey.attachment and similar in any supporting version of iOS (e.g. .attachment is available since iOS 7) within a Swift 4 project. #available doesn't apply because it's a Swift language version difference rather than an OS version difference.
Ensure your pod is set to the correct Swift version and it should then work as expected. You can tell CocoaPods that by adding a .swift-version file at the top of your project:
$ echo 4.0 >.swift-version
This magical version file is mentioned in passing in a CocoaPods blog post from last year: http://blog.cocoapods.org/CocoaPods-1.1.0/

Clustering with MapKit using Xcode 8+ and Swift 3+

I'm trying to use a third party solution for clustering annotations with MapKit.
I found this pod Cluster - https://github.com/efremidze/Cluster that seems to be for Swift 3.
Their example runs ok and I followed their guide for installations but I'm coming up with numerous errors.
Error ClusterManager has no member 'zoomLevel'
manager.zoomLevel = 17
Error Value of type Annotation has no member 'type'
annotation.type = .color(color, radius: 25)
Error Extra argument 'visibleMapRect' in call
manager.reload(mapView, visibleMapRect: mapView.visibleMapRect)
You have installed Cluster (1.0.5), that's why the error is shown. Please update your pod using pod update command or install Cluster 1.0.6
copy all files from "Sources" downloaded with demo, into your project

Firebase error with swift code

I have try everythng and I have imported pods to my project, done it several times in several new projects, but always get this error:
'Cannot call value of non-function type 'module'
Is it possible that my cocoa-pods are damaged somehow?
When I insert this code:
import Firebase
let BASE_URL = "my_project_url"
var FIREBASE_REF = FIRDatabase.database().reference()
I can see in Output/Debug window that I am connected with firebase, but when I start with code:
let BASE_URL = "my_project_url"
let FIREBASE_REF = Firebase(url: BASE_URL)
var CURRENT_USER: Firebase
{
let userID = NSUserDefaults.standardUserDefaults().valueForKey("uid") as! String
let currentUser = Firebase(url: "\(FIREBASE_REF)").childByAppendingPath("users").childByAppendingPath(userID)
return currentUser!
}
always get error. I have really try stuff from a lot tutorials, I tried a lot of things over past few days and nothing happened.
I have also look and read this topics, but did not help:
Cannot call value of non-function type 'module'
xcode error : Cannot call value of non-function type module Firebase
Unable to connect Firebase to my Xcode swift app?
I have open many new projects, done it import pod many times, I have import pod with insert in my pod file:
pod "Firebase"
and like this:
pod "Firebase"
pod "Firebase/Database"
also tried like this:
pod 'Firebase', '>= 2.5.1'
pod "Firebase/Database"
but always the same problem. Pods are inserted, I see Firebase folder and I know this is OK, so what could be wrong?
Like I said, I see that I am connected with Firebase in Debug window, as soon I start coding, error appears, and it is in every project like this, even when I try different approach and different code.
Any ideas?
You're either using the wrong version of Firebase, or following the wrong guide, depending on what you're trying to do.
Your pod config will install the latest version (3.2.1) while the code you've written is for 2.5.1 and before.

Failed to recognize AWSDynamoDB with XCode 7.0 Beta, iOS 8.3, and aws-ios-sdk-2.2.0

I am matching guides for using AWSDynamoDB in a test project using Swift 2 in XCode 7.0 Beta. I am required to use that platform instead of the previous stable one and make it work.
I am using the next links:
https://docs.aws.amazon.com/mobile/sdkforios/developerguide/setup.html
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LoadData_Java.html
Best way to make Amazon AWS DynamoDB queries using Swift?
I already made it work for reading and writing text files and images to an S3 Bucket, but now that I am trying to use DynamoDB service something might be missing.
Here is my Podfile contents:
# Uncomment this line to define a global platform for your project
platform :ios, '8.3'
target 'AWSSDKTest' do
source 'https://github.com/CocoaPods/Specs.git'
pod 'AWSCore'
pod 'AWSAutoScaling'
pod 'AWSCloudWatch'
pod 'AWSDynamoDB'
pod 'AWSEC2'
pod 'AWSElasticLoadBalancing'
pod 'AWSKinesis'
pod 'AWSLambda'
pod 'AWSMachineLearning'
pod 'AWSMobileAnalytics'
pod 'AWSS3'
pod 'AWSSES'
pod 'AWSSimpleDB'
pod 'AWSSNS'
pod 'AWSSQS'
pod 'AWSCognito'
end
target 'AWSSDKTestTests' do
end
I had to delete Podfile.lock and Pods folder, deleted Configuration Sets in Project->Info->Configurations, and installed pods again.
Here is my bridging.h file:
#ifndef AWSSDKTest_bridging_h
#define AWSSDKTest_bridging_h
#endif
#import <AWSCore/AWSCore.h>
#import <AWSS3/AWSS3.h>
#import <AWSDynamoDB/AWSDynamoDB.h>
#import <AWSSQS/AWSSQS.h>
#import <AWSSNS/AWSSNS.h>
#import <AWSCognito/AWSCognito.h>
I downloaded the aws-ios-sdk-2.2.0.zip file, unzipped and added to Frameworks all the AWS frameworks.
I am trying to use AWSDynamoDBModel, here is a swift file for implementing the Upload Sample Items Example for using DynamoDB Mapper:
import Foundation
class Forum : AWSDynamoDBModel, AWSDynamoDBModeling {
var name : String = ""
var category : String = ""
var threads : Int = 0
var messages : Int = 0
var views : Int = 0
// override init!() { super.init() }
required init!(coder: NSCoder!) {
fatalError("init(coder:) has not been implemented")
}
class func dynamoDBTableName() -> String! {
return "Demo"
}
class func hashKeyAttribute() -> String! {
return "email"
}
class func rangeKeyAttribute() -> String! {
return "date"
}
/*
override init(dictionary dictionaryValue: [NSObject : AnyObject]!, error: NSErrorPointer) {
super.init(dictionary: dictionaryValue, error: error)
}
override func isEqual(anObject: AnyObject?) -> Bool {
return super.isEqual(anObject)
}
*/
}
I had to comment the lines that caused error because those might be fixed. The errors mentioned that those functions couldnt be overridden and that super.init couldnt be called inside a root method.
After cleaning and building again, the error is at the class declaration line
class Forum : AWSDynamoDBModel, AWSDynamoDBModeling {
The error says: Use of undeclared type 'AWSDynamoDBModel'
If I try writing other AWSDynamoDB classes they don't appear in the list of suggestions and then cause the same error.
Additionally I want to mention that in the developer's guide setup (first link above) the 4th point of the Getting Started with Swift section says: "Import the AWSCore header in the application delegate":
#import <AWSCore/AWSCore.h>
Than can't be done, only in the bridging.h file which is mentioned in the 2nd point.
My first request of assistance is in fixing the error mentioned and making the project recognize the AWSDynamoDB framework.
Then I request your help for any observation about this merge of different tutorials, also any other online tutorial or guide that is more clear than those mentioned.
In case you are using CocoaPods (0.36) with "use_frameworks!", this answer might solve your problem:
"Normally when you’re importing Objective-C code into Swift, you do so by including the header of the file containing that code in the “Bridging Header” for your project. And that is indeed how you include code from a static library (which your pods used to be.)
But it is not how your import Objective-C code from a Framework. To do that you simply type…
import Framework
…inside your Swift file that’s using the Objective-C class (where “Framework” is the name of the actual Framework containing the class.)"
Source here: http://rogueleaderr.com/post/115372471213/unresolved-identifier-in-swift-when-importing
I think the problem is not related to Xcode7Beta, but the installation process of your project. (My sample DynamoDB project runs fine under Xcode7Beta.)
If you installed the AWS Mobile SDK via cocoapods, you neither have to worry about the bridging file nor need to download aws-ios-sdk-2.2.0.zip file since cocoapods already did everything for you.
My suggestion would be:
clean your project, remove all aws related frameworks, bridging files that you manually added,delete Podfile.lock and Pods folder and AWSSDKTest.xcworkspace file, and the re integrate pods by running "pod install"
Open your project using Xcode 6.4, confirm it can be built and run successfully under Xcode 6.
If everything looks good via Xcode 6, reopen it via Xcode7Beta, If it failed to compile, please post the error output so I can take a look.
Thanks

Resources