YouTube-Player-iOS-Helper can't use YTPlayerView class - ios

I am trying to implement the youtube-ios-player-helper, found here: https://github.com/youtube/youtube-ios-player-helper
What I did:
Edited my podfile, pod update, everything fine without any errors, Alamofire - which was also added via cocoapods still working
I can see the Pod in my workspace, and I can even select YTPlayerView as Class for my UIView in Storyboard
But when it comes to adding the IBOutlet it doesn't recognize the YTPlayerView Class anymore?!
Shouldn't it be impossible to even select it in storyboard if the Pod wasnt properly added?
I also tried the "manual" method, that gave a slightly better result as it would let me define the Player, but wouldn't let me import the YTPlayerView via Bridging-Header

The YTPlayerView is in the separate Pods module which you need to import.
My Podfile:
platform :ios, '8.3'
target 'MyApp' do
use_frameworks!
pod 'youtube-ios-player-helper'
end
Your Swift file:
import UIKit
import youtube_ios_player_helper // You're missing this line
class MyView: UIView { // Some class
#IBOutlet var playerView: YTPlayerView!
// ...
}
If import youtube_ios_player_helper doesn't work for you, you can add #import "YTPlayerView.h" to your bridging header as stated in Fayza Nawaz's answer.

I faced the issue and fixed it by adding
"#import YTPlayerView.h"
in bridging header file in my project. To learn about bridging header, check this link: adding bridging header in swift ios. I hope it'll help you.

Related

Swift google firebase VisionTextDetector showing Use of undeclared type

My scenario, I am trying to implement Google Firebase CoreML for text detection. Here, I installed a list of pods into my project but I still get Use of undeclared type 'VisionTextDetector'. How to fix this?
pod 'Firebase/Core'
pod 'Firebase/MLVision'
pod 'Firebase/MLVisionTextModel'
pod 'Firebase/MLVisionFaceModel'
pod 'Firebase/MLVisionBarcodeModel'
pod 'Firebase/MLVision'
pod 'Firebase/MLVisionLabelModel'
Below is my class file:
import UIKit
import Firebase
class TextViewController: UIViewController {
lazy var vision = Vision.vision()
var textDetector: VisionTextDetector? // Error: Use of undeclared type 'VisionTextDetector'
}
As the documentation didn't mentioned about the actual framework to be imported which is FirebaseMLVision, so with or without "Firebase", you much import actual "MLVision" framework. Just add below line on the top of your class file.
import FirebaseMLVision
Let me know, if you still face that error!
VisionTextDetector is no more supported so you have to use VisionTextRecognizer. no need to import FirebaseMLVision

I've tried it all, but I can't import my Swift file to my Objective-C file

I've read though multiple threads on this on StackOverflow, and I can't seem to find the answer to my problem. My folder hierarchy is like this:
"Project Name"
- "Helpers"
"FileIWantToImport.swift"
"FileIWantToImportTo.m"
I have:
Set the build settings to have a Product Module Name FMB
Set Defines Modules to YES
a bridging header created by Xcode
cleaned my build
#import FMB-swift.h in my AppDelegate with out any problems
Added #objc to my class declaration in my file so it says #objc class MyClass: NSObject
HOWEVER. I cannot, for the life me, figure out why it won't import into FileIWantToImportTo.m
I have tried:
#import "FMB-swift.h"
#import "Helpers/FMB-swift.h"
#import "Product Name/Helpers/FMB-swift.h"
#import <FMB-swift.h>
#import <Helpers/FMB-swift.h>
#import <Product Name/Helpers/FMB-swift.h>
All I get is "file not found" error. Can someone please point me in the right direction? I've looked through all the other threads and the apple docs and can't figure it out. I'm running in Xcode 7 and 10.11 GMs if that makes a difference.
EDIT: Here is an example project https://github.com/Aghassi/Example-Project
This is what you need to do:
Create a Swift file in your ObjC based project. No need to create bridging headers, since they're used to see ObjC code from swift, not swift code from ObjC.
In your Target, under Build Settings set Embedded Content Contains Swift Code to Yes
Your Swift file should have an #objc public class.
#objc public class Example: NSObject {
public func printSomething(text: String) {
print(text);
}
}
Check your Project's name, and in your .m file, add #import <ProjectsName-Swift.h>, and you should be able to instantiate your class defined in the Swift file, and all it's public methods. You might need to build your project before importing the -Swift.h file.
Here's an example project with an ObjC class using Swift code: https://github.com/lucaslt89/Example-Project.git

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

PureLayout in Swift with Cocoapods

Using cocoapods-0.37.2 Here's my Podfile:
platform :ios, "8.0"
use_frameworks!
pod "GoogleMaps"
pod 'FontAwesomeKit'
pod 'PureLayout'
I'm trying to import PureLayout in my .swift file like this:
import PureLayout
class ViewController: UIViewController {
...
But I get error:
No such module 'PureLayout'
Why??? I thought that Cocoapods creates -Bridging-Header.h by itself when using use_frameworks! ?
I did not use the use_framework option but I used PureLayout in Swift with CocoaPods without issues.
My Podfile only has one line pod 'PureLayout'.
I created the <Your Module>-Bridging-Header.h file myself as instructed by Apple here. I added a line #import "PureLayout.h". I've also updated my target build settings to enter the bridging header file name as per instructions.
In the .swift file where I want to use PureLayout, I did not need to have import PureLayout. It would give me an error as you mentioned. The auto layout calls would just work, since it's defined through bridging header.
One side point - the test target would fail to compile if you add bridging header file to its build settings. So make sure the bridging header update is done on target not project level.
I guess the current README in PureLayout github page is a bit outdated, since it currently asks you to do import PureLayout in the .swift file. I added a comment in this README enhancement issue too.
install the podfile
open your .xcworkspace
put your import PureLayout statement in, get the error
delete the statement
clean your product
build your product
put your import PureLayout statement back in
This has been common occurence and fix for me when using outside frameworks.
spacemonkey's method work for me. In that case, you don't even need a -Bridging-Header.h file.
As for FontAwesomeKit, since it contains some resource file(xx.ttf, xx.otf, etc), you should add this file to project to make it work. Like following shows:
Clean your project and recompile, then you are done.
Following is my demo for this:
import FontAwesomeKit
import ChameleonFramework
import SnapKit
class ViewController: UIViewController {
#IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let iconSize : CGFloat = 128;
let codeIcon = FAKFontAwesome.codepenIconWithSize(iconSize);
imageView.image = codeIcon.imageWithSize(CGSizeMake(iconSize, iconSize));
view.backgroundColor = UIColor.flatGreenColorDark();
}
}
PS. Since you use swift, maybe the SnapKit Layout framework will much suitable than PureLayout.

How to send emails in Swift using Mailgun

I have the need to send automatic emails in a Swift project I'm working on. So far my best lead seems to be using Mailgun. (I'm open to better options if anyone has liked something else)
Swift is not listed in the Mailgun API Reference in their documentation, and I didn't see objective-c either. The only article speaking at all about his I've found is this one.
Update
I've been trying to piece together everything and this is where I've gotten so far.
I was able to get Mailgun installed via cocoapods. Using it in Swift has been kinda tricky.
I setup cocoapods with the following pod file:
target 'TestApp' do
pod 'mailgun', '~> 1.0.3'
end
target 'TestAppTests' do
end
With this podfile I was able to run pod install and set up the dependencies. Then I setup an Objective-C-Bridging Header in build settings. I used the following objective-C bridging header.
#ifndef Promises_Promises_Bridging_Header_h
#define Promises_Promises_Bridging_Header_h
#import <mailgun/Mailgun.h>
#import "testMail.h"
#endif
I was getting a linking error for awhile, but I needed to have the project opened via the workspace and I had to go to Product -> Schemes -> Edit Schemes and add the Pods-mailgun to the top of the list and then it would let me build.
Now I want to take advantage of the MailGun API. The docs say to do the following.
Mailgun *mailgun = [Mailgun clientWithDomain:#"samples.mailgun.org" apiKey:#"key-3ax6xnjp29jd6fds4gc373sgvjxteol0"];
[mailgun sendMessageTo:#"Jay Baird <jay.baird#rackspace.com>"
from:#"Excited User <someone#sample.org>"
subject:#"Mailgun is awesome!"
body:#"A unicode snowman for you! ☃"];
I think i am facing exactly the same problem with you. But I am a little confused on how many .h and .m files you have used and what each one contains. I am clueless on obj C so I try to follow you blindly.
Correct me if I am wrong.
• You have one .h bridging header file that contains:
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "AFNetworking.h"
#import <mailgun/Mailgun.h>
• You have one .m file that contains:
#import <Foundation/Foundation.h>
#import <mailgun/Mailgun.h>
#interface mailTest: NSObject
- (void) sendMail: (NSString*)email;
#end
• And in your Viewcontroller.swift you have (lets say in a button) this:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
#IBAction func myButton(sender: UIButton) {
var test: mailTest = mailTest()
test.sendMail("testemail#testemail.com")
}
}
Is that correct?
There's another option that you could try if you wanted as much as possible to be on the Swift side:
If you don't have a bridging header yet, create a dummy objective-c file (add new file to project). Xcode will ask if you will like to add a header file (this will sort out the header for you automatically)
Add this to your bridging header (providing you already imported mail gun using cocoa pods):
#import "mailgun/Mailgun.h"
Import maligun in your swift class:
import mailgun
Simply use mailgun's API in swift as you would in Objective-C:
#IBAction func sendEmail(_ sender: Any) {
let mailgun = Mailgun.client(withDomain: "samples.mailgun.org", apiKey: "key-3ax6xnjp29jd6fds4gc373sgvjxteol0")
mailgun?.sendMessage(to: "Jay Baird <jay.baird#rackspace.com>", from: "Excited User <someone#sample.org>", subject: "Mailgun is awesome!", body: "A unicode snowman for you! ☃")
}
At this point I've answered my own question. The process isn't too terrible. Install mailgun using cocoapods.
Link the objective-c code that is needed using an objective-c bridging header.
Create an objective c file to house your method that will call the mailgun operation, and use it.
#import <Foundation/Foundation.h>
#import <mailgun/Mailgun.h>
#interface mailTest: NSObject
- (void) sendMail: (NSString*)email;
#end
Then in my swift code I just call:
var test: mailTest = mailTest()
test.sendMail("testemail#testemail.com")
Here is the mailTest header file. I created a .m file that implements the sendMail method and calls the code from the API and it works great. The only other thing that could be challenging is setting up the mailgun account and configuring your domain so that emails can be sent, but that isn't code related.

Resources