TwitterKit Timeline not loading - ios

I have installed TwitterKit via CocoaPods due to it not being available in the Fabric OSX app. I'm trying to get a timeline view integrated into the app. It acts like it's loading but never shows any output in the console and never actually loads anything.
import UIKit
import TwitterKit
import Fabric
class updatesTVC: TWTRTimelineViewController{
convenience init() {
let client = TWTRAPIClient()
let dataSource = TWTRUserTimelineDataSource(screenName: "resurrectionwv", apiClient: client)
self.init(dataSource: dataSource)
}
}

Related

created a small framework but showing init error in swift

I am trying to create my first framework ,
What I am trying to do is, I have added one public method to read the config json (dictionary) from app level. So I need app to pass this config dictionary and read using framework.
I have add framework all correctly and then imported it in app and tried to create instance but getting following error
“ 'Platform' initializer is inaccessible due to 'internal' protection leve
“
Here. “Platform is framework name.
Here is the code in framwork side
import Foundation
public class Platform {
public init(){
}
public func readConfigFileFromApp(config:Dictionary<String, String>) {
print (config)
//Read the configfile from app and save it here for rest of the SDK use
}
}
On app side i tried this line
import UIKit
import Platform
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let platform = Platform() . **//Getting error 'Platform' initializer is inaccessible due to 'internal' protection level**
// Do any additional setup after loading the view.
}
}
please help

getting Firebase Cloud messaging running swift

I am following Google's instructions on setting up Firebase https://www.firebase.com/docs/ios/quickstart.html
I suspect the problem may be because the help is for the legacy version. However deprecated should not read an error, at least I have found this for apple deprecations. The following code:
import UIKit
import Firebase
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var myRootRef = Firebase(url:"https://<YOUR-FIREBASE-APP>.firebaseio.com")
// Write data to Firebase
myRootRef.setValue("Do you have data? You'll love Firebase.")
// Do any additional setup after loading the view, typically from a nib.
}
gives the following error
Cannot call value of non-function type 'module<Firebase>'
From the link, this is the exact same code prescribed. I have installed pods for Firebase and Firebase Cloud Messaging.
Cannot call value of non-function type 'module'
The error is saying that you imported a module named Firebase here:
import UIKit
import Firebase
And then you tried calling the module as if it's a function:
override func viewDidLoad() {
super.viewDidLoad()
var myRootRef = Firebase(...)
I think the old Firebase module must have defined a function/class called Firebase, so that when you imported the old Firebase module, that made the Firebase() function/initializer available. Apparently, the new Firebase module doesn't define that function/class anymore, hence the need for the new instructions.
In addition, your url can't be correct:
url:"https://<YOUR-FIREBASE-APP>.firebaseio.com"
You would substitute the actual name of your app in place of <YOUR-FIREBASE-APP>.
In any case, you don't specify a url in your code anymore: instead you call FIRApp.configure() in AppDelegate.swift, and that takes care of connecting to the proper url for you. How does configure() know which url to connect to? Look in the GoogleService-Info.plist file that you dragged into your app--you’ll see the db url in there.
To get a reference to the top of your db, all you do is:
dbRef = FIRDatabase.database().reference()
Here it is in a ViewController:
class ViewController: UIViewController {
var dbRef: FIRDatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
dbRef = FIRDatabase.database().reference()
dbRef.child("person").child("name").setValue("Joe")
After running your app, you'll see something like the following at the Firebase website:
abcd-1234
|____person
|__name: “Joe”
I found a tutorial that works. Its by google so its up to date with the new Firebase.
https://codelabs.developers.google.com/codelabs/firebase-ios-swift/#0

How to import a project into Xcode

I am attempting to integrate the Yelp API into my iOS app. From the existing yelp documentation for objective C, we downloaded their Xcode project and dragged it into our project. However, when trying to call and import the project in my swift file, we have errors. Here is what I mean:
func getYelpData(mapItem:MKMapItem) {
var term: String = (NSUserDefaults.standardUserDefaults().valueForKey("term") ?? "") as! String;
var location: String = (NSUserDefaults.standardUserDefaults().valueForKey("location") ?? "") as! String
var APISample: YPAPISample = YPAPISample() // Use of undeclared type 'YPAPISample'
and at the top of the class I try to import the YPAPISample like so
import YelpAPISample
but it does not allow me to do this either.
I'm new to swift programming so any help would be greatly appreciated!
It's one of the most regularly asked question regarding Swift on SO.
Apple provided a document here for such purpose:
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
In short, you'd need to create a bridge header to import the Objective-C framework. Not all the framework can be import directly in Swift.
To add it manually, search bridging in build settings: (Make sure you select All)

Google analytics objects in SWIFT classes that have test target membership gives compile error

I've been successfully using Google Analytics for iOS for a while in some other applications using SWIFT. However, I've run across a specific scenario that I cannot seem to solve.
I have an AnalyticsHelper class that has a simple method that sends an event to Google through my default tracker. When I try to create an instance of this AnalyticsHelper class in any other class in my project that has target membership in my test target, it doesn't recognize the AnalyticsHelper object and gives a compile error. However, creating an instance of this AnalyticsHelper class in any other class that does NOT have target membership in my test target works just fine.
If I try to add my AnalyticsHelper class to my test target, I get a compile error in my AnalyticsHelper class because it can't identify any of the Google Analytics objects (Use of unresolved identifier 'xxx'). Seems like it may be some type of linker error, but I can't seem to figure it out.
Any idea how to solve this issue? I'm using Xcode 6.1.1 (6A2008a), Google Analytics 3.09.
AnalyticsHelper class:
import Foundation
public class AnalyticsHelper {
func logBarcodeScan() {
let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIScreenName, value: "Scanning")
tracker.send(GAIDictionaryBuilder.createEventWithCategory("UX", action: "scanBarcode",
label: "bagTag", value: nil).build() as NSDictionary)
tracker.set(kGAIScreenName, value: nil)
}
}
Class that doesn't have target membership in my test target, creates instance of AnalyticsHelper without any problem:
import UIKit
class StartViewController: UIViewController {
let analyticsHelper = AnalyticsHelper()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
Class that does have target membership in my test target, gives an unresolved identifier 'AnalyticsHelper' error on compile:
import UIKit
import AVFoundation
class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
let analyticsHelper = AnalyticsHelper()
}
I finally discovered the answer.
1) In the Test Target Build Settings, set the Objective-C Bridging Header file setting to the same file your App target uses for this setting.
2) In the Test Target Build Phases, add the libGoogleAnalyticsServices.a to the Link Binary With Libraries section, along with the other 3 frameworks that Google Analytics requires (CoreData, SystemConfiguration, libz.dylib).
After these steps, everything worked for me.

Can't get Core Bluetooth to work in Swift iOS playground

I am new to swift. I am not able to get a callback to centralManagerDidUpdateState:: w/ following in playground (i.e.: i thought initialization would call back into centralManagerDidUpdateState):
import CoreBluetooth
class BTDiscovery:NSObject,
CBCentralManagerDelegate {
func centralManagerDidUpdateState(central: CBCentralManager!) {
println("here")
}
}
var bt = BTDiscovery()
Is Core Bluetooth supporting in the iOS Swift playground?
I tried this for OSX playground and IOBluetooth. This also didn't work. What am I doing wrong?
Thank you.
I think what you're running into is the playground is inherently synchronous while the BlueTooth discovery is asynchronous. To allow it to work you need to add some things to your playground to allow asynchronous operation:
import XCPlayground
XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)
Also note that since the iOS playground is run on the simulator, I wouldn't necessarily expect CB to work there at all.
You also have more fundamental problems in that you're not doing anything to actually trigger discovery. You need to create an instance of CBCentralManager and use it to drive the discovery process:
import Cocoa
import XCPlayground
import CoreBluetooth
class BTDiscovery:NSObject, CBCentralManagerDelegate {
func centralManagerDidUpdateState(central: CBCentralManager!) {
println("here")
}
}
var bt = BTDiscovery()
var central = CBCentralManager(delegate: bt, queue: dispatch_get_main_queue())
XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)
You can only use Core Bluetooth on an actual iOS device; it is not supported in the simulator, and by extension, it is not supported in a Playground as this is also executing on your Mac rather than on an iOS device.
Either XCPSetExecutionShouldContinueIndefinitely nor PlaygroundPage.current.needsIndefiniteExecution will work.
Please keep in mind CoreBluetooth only works on device. Which means currently it won't work on the Playground.
It's possible to use Bluetooth in Swift Playground. Please note you have to use PlaygroundBluetooth. You can find more informations about it here Documentation Framework PlaygroundBluetooth
This is how you can scan using the central.
let managerDelegate: PlaygroundBluetoothCentralManagerDelegate = <# manager delegate instance #>
let manager = PlaygroundBluetoothCentralManager(services: nil)
manager.delegate = managerDelegate
Please note PlaygroundBluetooth is just a subset of CoreBluetooth therefore you can not do everything which is normally possible in CoreBluetooth, but I think it's still great for simple things to have fun with.

Resources