0

I want badge on a BarButton and I came across BBBadgeBarButtonItem but I am not sure if this will work in swift or not.

  1. is it possible ?
  2. if yes how ?

PS I am very new to iOS and swift

When I try to use it like the readme file says, I am getting an error at import line "Expected Identifier at import declaration"

T_C
  • 3,148
  • 5
  • 26
  • 46
  • Try it and then ask a question if you run in to a specific problem. – Dash May 31 '15 at 21:49
  • adding a import statement is failing for me, when I write import "BBBadgeBarButtonItem.h" in my view controller.swift i get an error "Expected identifier in import declaration" Is it because when I dropped the files in my project it did not ask for bridge file – T_C May 31 '15 at 22:01

2 Answers2

2

Import it in you bridging header like this:

#import <BBBadgeBarButtonItem/BBBadgeBarButtonItem.h>
Morten Holmgaard
  • 7,484
  • 8
  • 63
  • 85
1

You need what's called an Objective-C bridging header since BBBadgeBarButtonItem is written in Objective-C and your project is Swift.

See http://www.learnswiftonline.com/getting-started/adding-swift-bridging-header/ on how to create the bridging header.

Once you've properly created your bridging header you'll then add the following to it:

#import BBBadgeBarButtonItem.h

You should then be able to do something like (untested):

let customButton = UIButton()
let barButton = BBBadgeBarButtonItem(customUIButton: customButton)
barButton.badgeValue = 1
Kyle Decot
  • 20,715
  • 39
  • 142
  • 263