When I have imported the SDWebImage framework into my project.
I get 2 warning messages.
They all say 'Duplicate definition of category "WebCache" on interface "UIImageView" '
Besides, there is one also shown 'In module "WebImage" import from <built-in>:1: '
How to hide or make sure it won't show out anymore?
Note:
The Framework imported, and linked with binary files. And I'am using swift so that I linked the bridge as well -> "#import 《SDWebImage/UIImageView+WebCache.h》 "
Use #import SDWebImage; instead of #import <SDWebImage/UIImageView+WebCache.h> (not just in the bridge file but anywhere in your project).
Related
Note: This is a different question than importing generic swift files (which can be done using the Sources folder).
I have a playground with 2 pages and I would like to use a protocol defined in the first page in the second page. I'll use an example of JSON conversion.
JSON.xcplaygroundpage
import Foundation
protocol JSONConvertible {
func jsonValue() -> String
}
JSONArray.xcplaygroundpage
import Foundation
//Undeclared type JSONConvertible
extension Array : JSONConvertible {
}
I have tried the following imports:
import MyPlayground
import MyPlayground.JSON
import JSON
import JSON.Contents (in finder the file name is actually Contents.swift)
I have also tried adding JSON.xcplaygroundpage into the Source folder of JSONArray as well as the Resources folder.
Note: I realize that I could put the protocol definition in a separate JSON.swift and include that in my project Sources folder. That doesn't really answer my question.
This is working in Xcode 8.3.3.
For code common to multiple pages, put it in separate files under top-level Sources group. Be sure to have proper Swift access control keywords in the right places.
Note from http://help.apple.com/xcode/mac/8.2/#/devfa5bea3af:
...the auxiliary Swift source file must export it using the public keyword. This includes classes, methods, functions, variables, and protocols.
Common.swift:
public class DoIExist { public init(){ print("Woot!")} }
Then you can reference it in all of the other pages. Like this:
Page2:
//: [Previous](#previous)
let d = DoIExist()
//: [Next](#next)
You can see that it works because of the console output ("Woot!") and the view results gutter.
To achieve this, I followed the directions at the Apple Xcode documentation about Playgrounds. When Apple inevitably moves those docs and does not provide a forwarding link, read on for how I found it.
I searched for the clues found in the link in cocoapriest's answer: "ios recipes Playground Help Add Auxilliary Code to a Playground". This leads to a document Apple is currently calling "Xcode Help" in a chapter titled "Use playgrounds" in a section titled "Add auxiliary code to a playground".
Just got this to work with this instruction by Apple: https://developer.apple.com/library/ios/recipes/Playground_Help/Chapters/AddAuxilliaryCodetoaPlayground.html
Make sure to declare your classes are public. Also, I had to re-start the Xcode to take the effect.
If I have a structure:
/app/views/tags/tag1.scala.html
/app/views/mystuff/tags/tag2.scala.html
Then, inside tag2.scala.html
#import tags._ // this refers to /app/views/mystuff/tags
#import _root_.tags._ // I want it refers to /app/views/tags
Then I have an error: object tags is not a member of package
Q: what is the best practice to handle imports if the view-structure is deeper than one level ?
REMARK:
I've already read that _root_ can not be imported. But how can I refer to the root then?
UPDATE:
If I try this (not to use root):
#import views.tags._
#import views.mystuff.tags._
Then I have error: object tags is not a member of package views
For now I follow different structure:
tags/tag1.scaa.html
tags/mystuff/tag2.scala.html
and this of course works (maybe this is even better).
Another idea is to create separate play module. Or even different (rest) application.. depending on what 'stuff' is in each concrete case.
So this is alternative solution, I don't know how to refer to root in that case:
The package "views" need to be the last in structure path, so you must change your structure from:
/app/views/mystuff/tags/tag2.scala.html
to:
/app/mystuff/tags/views/tag2.scala.html
I added the Facebook sdk code to my project then I got this error because I already had a json library, so I deleted the Facebook json library from my computer and from the project but I still get this error. I search the whole project for "#interface SBJsonBase" and I only get one result. How can it say it's a duplicate when I only have one interface? Is it including the file twice? Does the search not always find everything?
May be this helps? Delete your derived data and do a clean project, then try to build again
I had a simular problem. It was a small search, but I could solve it without creating a new project etc...
The thing was I had a Class B that was importing Class A.
Then I had a class that imported Class B and also Class A.
When I did this, these problems occured.
Eg. A SOAP webservice Class imports all the Entities that are passed over the web.
Class goToSchoolWebservice.
import "person.h"
import "school.h"
...
Then I had a Singleton class used for caching that had the Logged in Person and also a ref to the webservice class.
import "person.h"
import "goToSchoolWebservice.h"
--> this is where is went wrong!!
So watch out for these circular references. ITs not so easy to detect them!
if your using #include instead of import then use this technique to minimize duplicates: at the begining of your interface (actually right before it) do check for a definition and if not defined then define it and proceed to define your interface. here is an example:
#ifndef __NetworkOptionsViewController__H // check if this has every been imported before
#define __NetworkOptionsViewController__H
#import "blahblah.h"
#interface NetworkOptionsViewController : UITableViewController
{
NSMutableArray* somevariable1;
int somevariable2;
}
#end
#endif
-- for me personally, i got this error though because the file path to my class was wrong. I checked file inspector and my class file was not defined in Classes folder even though the IDE said it was. I deleted them and copied them over again.
For those that still get this error, despite following header import conventions: I got this error from importing a header that had been deleted from the project. The missing header was instead found in an old backup of my project in dropbox (That I made before doing some destructive stuff in Git), and that file caused the circular import.
I solved a similar problem by moving all the imports to the prefix header file.
I wanted to try out PLActorKit for iPhone: http://code.google.com/p/plactorkit/
but I still get the error, that classes from this framework can't be found.
I downloaded the the .dmg file and added the ActorKit.framework to my project. In the class I want to use the framework I wrote
#import <ActorKit/ActorKit.h>
in the .h file.
When I try to use classes from the ActorKit framework in my .m file I still get the error
*_OBJC_CLASS_$_PLActorKit*, referenced from: Objc-class-ref-to-PLActorKit in myClass.o
Symbol(s) not found
I don't know what I did wrong.
where are the headers located? if they are in your classes directory then try using:
#import "ActorKit/ActorKit.h"
else you need to add the directory containing the headers to the headers search path. for whatever reason it can't currently find the headers, or the static framework/project isn't being built. you may have to set it up as a direct dependency.
I've got a couple of Core Data-generated class files that I'd like to add custom methods to. I don't need to add any instance variables. How can I do this?
I tried adding a category of methods:
// ContactMethods.h (my category on Core Data-generated "Contact" class)
#import "Contact.h"
#interface Contact (ContactMethods)
-(NSString*)displayName;
#end
...
// ContactMethods.m
#import "ContactMethods.h"
#implementation Contact (ContactMethods)
-(NSString*)displayName {
return #"Some Name"; // this is test code
}
#end
This doesn't work, though. I get a compiler message that "-NSManagedObject may not respond to 'displayName' " and sure enough, when I run the app, I don't get "Some Name" where I should be seeing it.
First go to your data model, select the entity you want to add methods to and change the class to something appropriate (I use the entity name with my initials at the beginning). Then select New File... from the File menu. From there select Managed Object Class (you have to do this while the data model is still the active document or you won't see this option). Step through the file wizard making sure to select the correct entity (Xcode will name the file correctly based on the class you entered earlier). Also make sure the Generate accessors and Generate Objective-C 2.0 properties options are selected. You should then be able to add any custom methods you want just like any other class. If you need any more help check out http://themikeswan.wordpress.com/2009/05/30/a-core-data-tutorial-part-2-polishing-the-basics/ I wrote this based on Mac OS X, but the concept is the same for iPhone.