39

Just updated pods for xcode 9 and I'm getting the error below for Cosmos.

enter image description here

Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'

Krunal
  • 77,632
  • 48
  • 245
  • 261
Chaudhry Talha
  • 7,231
  • 11
  • 67
  • 116
  • Share your pod info and swift language version. You've add a tag for swift3, so is it exact swift3 or swift3.x? – Krunal Oct 02 '17 at 06:29

7 Answers7

48

Note: Ensure swift language version of your project. Here is how you can see/check your swift language version.

enter image description here


You have two options as solution to your query:

  1. If your project has Swift versio 4.0
    - You should choose/download POD compatible to your project's swift language (Share me POD info and swift version, so I can provide you exact pod version version for your pod library suitable for project).

  2. If your project has swift version below 4.0
    - You need to migrate your project into Swift 4.0 (if you've not migrated it). Here is ref question and answer, how to migrate from swift (below) <4.0 to 4.0.


According to tag added by you in your question - Swift3 is your current project language version and pod 'Cosmos', '~> 12.0' is supporting swift 4.

pod 'Cosmos', '~> 12.0'

Here is list of previous release supporting Swift version below 4.0.

https://github.com/evgenyneu/Cosmos/releases

Try previous release of cosmos like:

pod 'Cosmos', '~> 11.0.3'
// or
pod 'Cosmos', '~> 11.0.1'
// or
pod 'Cosmos', '~> 11.0.0

'

Krunal
  • 77,632
  • 48
  • 245
  • 261
20
 attributes: [NSFontAttributeName: label.font]

it's seem okay with swift 3.2 . i fixed with paging menu viewcontroller library.

Ace
  • 219
  • 1
  • 3
16

In My case I replace This Code

[NSAttributedStringKey.font : font]

by Code Below

.size(attributes: [NSFontAttributeName : font])

Hope it Helps.

Avinash Mishra
  • 797
  • 9
  • 19
11

You must need to update swift version to 4.0 from Xcode.

Use below step

1) Choose Your Project from project manager (left top from Xcode)
2) Choose Build Settings
3) Search "Swift language"
4) Change "Swift Language Version " => Swift 4.0

iPatel
  • 46,010
  • 16
  • 115
  • 137
1
let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: .subheadline)
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
HafizAnser
  • 553
  • 6
  • 10
  • 1
    Thank you for this code snippet, which might provide some immediate help. A [proper explanation would greatly improve its long-term value](https://meta.stackexchange.com/q/114762/206345) by showing _why_ this is a good solution to the problem, and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you've made. – Virginia Dec 31 '18 at 13:42
0
let percentOff = NSMutableAttributedString(string: "\(productOff ?? "0")%OFF", 
attributes: [NSFontAttributeName: UIFont(name: "Montserrat-Regular", 
size: 13)!,NSForegroundColorAttributeName: UIColor.black,
 NSBackgroundColorAttributeName: UIColor.black])
    lblPriceDetail.attributedText = percentOff

This worked for me in swift 4.2

Vaibhav Gaikwad
  • 396
  • 5
  • 13
-1

Your pod might have a wrong swift version, not the project settings.

To change the pod swift setting, go in the file navigator (left of the screen) to Pods (blue icon) and select the pod you're having problems with. Then go to build settings and go to Swift Language version. Select Swift 4.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260