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
Related
I import a swift framework to a swift project, but when I call the class in this framework, Xcode throw a compile error "Use of undeclared type 'xxxx(class name)' ".
I feel Xcode have found the framework, otherwise it will complaint "can't find xxx(framework name)".
But why Xcode can't find the class of this framework.
I have tried remove and re-add framework, and delete DeivedData files, but all of them not work. I haven't use CocoaPods to import framework.
Any idea?
In a Framework that was built for Release (and not Debug), the class symbols need to be accessible.
Make sure you are you trying to access Public or Open classes from your Swift framework.
// set the Framework class to Public
public class rnHello{
// set the initializer to public, otherwise you cannot invoke class
public init() {
}
// set the function to public, as it defaults to internal
public static func world() {
print("hello from a static method")
}
}
Now you can access this via your Swift code or if you attach lldb using:
lldb) po rnHello.world()
Make sure that the FrameWorkSearch path in the BuildSettings of the project is reflecting the correct path to your framework.
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
I'm trying to get an example of running OpenEars with the RapidEars plugin running in Swift 2.2 (XCode 7.3.1). However, I suspect I'm having a larger issue with using Objective-C interfaces with extensions in a Swift project (or my understanding of how that works).
The OpenEars code is Obj-C. However I was able to get it running in my swift project through the standard Obj-C -> Swift translation techniques.
Abbreviated code follows. The full example is on a forked Github and updated to Swift-2.2: https://github.com/SuperTango/OpenEars-with-Swift-
This following example is working great. You can see the entire project by checkng out the "working-opears-swift2.2" tag.
OpenEarsTest-Bridging-Header.h:
#import <OpenEars/OELanguageModelGenerator.h>
#import <OpenEars/OEAcousticModel.h>
#import <OpenEars/OEPocketsphinxController.h>
#import <OpenEars/OEAcousticModel.h>
#import <OpenEars/OEEventsObserver.h>
ViewController.swift:
class ViewController: UIViewController, OEEventsObserverDelegate {
var openEarsEventsObserver = OEEventsObserver()
override func viewDidLoad() {
super.viewDidLoad()
loadOpenEars()
}
func loadOpenEars() {
self.openEarsEventsObserver = OEEventsObserver()
self.openEarsEventsObserver.delegate = self
var lmGenerator: OELanguageModelGenerator = OELanguageModelGenerator()
addWords()
var name = "LanguageModelFileStarSaver"
lmGenerator.generateLanguageModelFromArray(words, withFilesNamed: name, forAcousticModelAtPath: OEAcousticModel.pathToModel("AcousticModelEnglish"))
lmPath = lmGenerator.pathToSuccessfullyGeneratedLanguageModelWithRequestedName(name)
dicPath = lmGenerator.pathToSuccessfullyGeneratedDictionaryWithRequestedName(name)
}
func startListening() {
do {
try OEPocketsphinxController.sharedInstance().setActive(true)
OEPocketsphinxController.sharedInstance().startListeningWithLanguageModelAtPath(lmPath, dictionaryAtPath: dicPath, acousticModelAtPath: OEAcousticModel.pathToModel("AcousticModelEnglish"), languageModelIsJSGF: false)
} catch {
NSLog("Error!")
}
}
// A whole bunch more OEEventsObserverDelegate methods that are all working fine...
func pocketsphinxDidStartListening() {
print("Pocketsphinx is now listening.")
statusTextView.text = "Pocketsphinx is now listening."
}
Up until this point, everything is working great.
However, In order to use the "RapidEars" plugin, the documentation (http://www.politepix.com/rapidears/) says to:
Add the framework to the project and ensure it's being included properly.
import two new files (that are both "categories" to existing OpenEars classes):
#import <RapidEarsDemo/OEEventsObserver+RapidEars.h>
#import <RapidEarsDemo/OEPocketsphinxController+RapidEars.h>
Change methods that used: startListeningWithLanguageModelAtPath to use startRealtimeListeningWithLanguageModelAtPath
add two new OEEventsObservableDelegate methods.
func rapidEarsDidReceiveLiveSpeechHypothesis(hypothesis: String!, recognitionScore: String!)
func rapidEarsDidReceiveFinishedSpeechHypothesis(hypothesis: String!, recognitionScore: String!)
The new code can be found by checking out the rapidears-notworking-stackoverflow tag from the above github repo
Problem 1:
When doing completion in the XCode editor, the editor sees WILL perform autocompletion on the startRealtimeListeningWithLanguageModelAtPath method, however when the code is run, it always fails with the error:
[OEPocketsphinxController startRealtimeListeningWithLanguageModelAtPath:dictionaryAtPath:acousticModelAtPath:]: unrecognized selector sent to instance 0x7fa27a7310e0
Problem 2:
When doing auto completion in the XCode editor, it doesn't see the two new delegate methods defined in RapidEarsDemo/OEPocketsphinxController+RapidEars.h.
I have a feeling that these are related, and also related to the fact that they failing methods are defined as Categories to Objective-C classes. But that's only a guess at this point.
I've made sure that the RapidEars framework is imported and in the framework search path.
Can anyone tell me why this is happening? Or if there's some Swift magic incantation that I missed?
The problem could be the one described in the link below, where category methods in a static library produce selector not recognized runtime errors.
Technical Q&A QA1490: Building Objective-C static libraries with categories
I am following http://guides.cocoapods.org/making/using-pod-lib-create guide to created my own swift library.
Briefly steps:
pod lib create MyLibrary
And the question with Yes,Swift etc. (Example project created)
Created my own class ABXXXView to replace the default in 'Pods/Development Pods/MyLibrary/pod/Classes/ReplaceMe.swift'
Then i want to make an example in Example for MyLibrary in ViewController.swift, when i used the class ABXXXView under my own pods, i got the error as title described:
import MyLibrary
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let vi = ABXXXView()
self.view.addSubview(vi)
}
}
Which means can't find "ABXXXView", but i have import MyLibrary, any hint? Thanks!
EDIT:
If i recreated a project with Objc language, everything works fine.
Add the scope of your class "ABXXXView" to public.
public class ABXXXView : UIView {
}
I hope it will solve your problem.
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.