Imported subclasses not recognised - xcode

I'm trying to use the CVCalendar framework but Xcode doesn't seem to recognise the files, so perhaps I am importing them wrong.
In Storyboard however I can change a views class to any of the CVCalendar subclasses, it's just in my view controller that the files aren't recognised and when linking my storyboard views I'm getting undeclared type errors.
The instructions were to simple copy the folder containing all of the swift files into my project which I did and copied if required.
Did I miss something?

Related

How to get your custom content drawn in Interface Builder?

I watched the "What's New in Interface Builder" session video and tried to replicate the code that was showed but unfortunately when I assign a view to my custom class which has #IBDesignable I get 2 errors:
Main.storyboard: error: Live Views: Failed to update auto layout status: The bundle “swiftTest” couldn’t be loaded because its executable isn’t loadable.
Main.storyboard: error: Live Views: Failed to render instance of _TtC9swiftTest14ControllerView: The bundle “swiftTest” couldn’t be loaded because its executable isn’t loadable.
Later on in the video I saw that to have Live Views you have to make these steps:
1. Create framework
2. Create class
3. Mark as designable
How do I make the 1st step?
Thanks
As I understand it at the moment (prior to Xcode 6 Beta 3), #IBDesignable will only work from a view declared in a separate framework target.
However, I also struggled to add it because I had no "plus" button as described in various links (because the Hide Project & Target Lists arrow option was toggled off).
So, select your current project target, then just use the xcode menu options:
Editor > Add target...
Then select
Framework & Library > Cocoa Touch Framework etc.
By the way, to test #IBDesignable, this tutorial worked perfectly as a starting point:
http://www.weheartswift.com/make-awesome-ui-components-ios-8-using-swift-xcode-6/
One small but important thing to note in that tutorial (if you follow it onscreen instead of following on to its full github code listing) is that your view class must be prepended/decorated with #IBDesignable, e.g.
class CustomView : UIView {...}
should be
#IBDesignable class CustomView : UIView {...}
You should make new framework as a target for current project and add your live views in this framework. On General tab on main target you will see your framework in Embedded Binaries section.
I had a project with live views working and at one point I also had these error messages. This went away for me when closing XCode and restarting, fwiw.
It is working very well (and easily) for me with Swift in Xcode 6 Beta 5.
I've confirmed that with Xcode 6 Beta 5 I did not need to add any frameworks (for example, Cocoa Touch framework option under frameworks in the dialog that appears when adding a new project target). Nor did I need to add IBDesignable.h to the project. Both seem to be outdated requirements as per the the weheartswift.com write-up linked in the initial answer to the question.
All I needed to do was:
Prefix class definition of my custom Swift class source file
with keyword #IBDesignable
Prefix vars I wanted to show up in IB Attributes Inspector with #IBInspectable (IB recognizes several common variable types).
Then, after assigning my custom component's (UIControl subclass) name to IB's "Class" name file (under Identity Inspector tab, in right pane) replacing "UIView" -- e.g. the class name of the UIView placeholder object I originally dragged onto the IB VC's view -- upon selecting my custom component from the Content View component list in IB, I saw all my custom class' inspectable items show up in the IB Attributes Inspector!! Very cool.
Note: At first XCode would only allow me to prefix one variable with #IBInspectable. It showed errors on subsequent ones. Then, suddenly it seemed to work, and no more problems after that. Not sure if it was a typo or just took Xcode awhile to re-index my project and pre-compile or parse the code.
I code about #IBDesignable & #IBInspectable,
firstly, I got two errors like you,
then, I change the code I wrote,
you can checkout the code from my github
Good Luck.

Fail to load assembly on a MVC View

Some Context
I have one closed source asp.net MVC application distributed for several customers. I'm trying to develop a extension to include some very specific functionalities that will be used by a single customer (he will also have the extension source code).
I'm developing the extension as another mvc project, loaded as an area. I'm trying to avoid having to deploy the extension binaries in the main application '/bin' folder.
I'm loading the extension assembly and it's dependencies manually in the PreApplicationStartMethod of the main application assembly. The area registration process went fine and the area routes are registered as intended.
The Problem
When I try to load some extension pages, I got a "The view 'xx' or its master was not found or no view engine supports the searched locations." message. I investigated I little and replaced the view contents with a 'Hello' string. The view was rendered correctly.
I tried to produce a minimal that triggers the error and turns out it's the '#model'directive. I tried to figure out what's happening and It's an assembly loading error. I created a minimal view with '#model object' and tried to cast the Model to original type and got the following error message: "Could not load file or assembly 'xxx' or one of its dependencies. The system cannot find the file specified." (this assembly contains the class type used by the view)
Just to confirm the issue, I moved the mentioned assembly to the main application '/bin' folder and everything worked.
I also inserted some model manipulation instructions on the controller, just to investigate if an exception will appear but everything went fine, I could even render a grid using json.
I'm loading every assemly with:
var assembly = Assembly.LoadFrom(file)
BuildManager.AddReferencedAssembly(assembly)
There's something extra I need to do ?
Needed to add the assembly private path
AppDomain.CurrentDomain.AppendPrivatePath(pluginFolder);
Don't know the real explanation for it but I guess it's relates to the use of Assembly.LoadFrom(file) instead of Assembly.Load() and the fact that views are compiled later.

Importing Another Cocos2d Project's Classes, Code, and SRC

The project I was toying around with for some reason was a dated version of cocos2d, and the classes and methods I was trying to introduce were too recent. So, I have successfully installed the new cocos2d, and have created a cocos2d template in Xcode. My issue is that this project is brand new, and I want to bring all my other project's code into this.
I have searched this across other stackoverflow threads, and just dragged the files/folder into the new project. When the files wouldn't transfer, I adjusted their path, and then dragged them in, or in one unique case, when dealing with the class main.m, I just changed its internal code so that it would sync up with the rest of the code.
However, because this is a template file, there are some extra baggage classes that I am not sure how to handle. These classes are the classes that come standard in the 'Classes' folder when the cocos2d template is first created:
GameConfig.h
HelloWorldLayer.h
HelloWorldLayer.m
RootViewController.h
RootViewController.m
MyGameAppDelegate.h
MyGameAppDelegate.m
And then in the 'Other Sources' folder:
MyGame_Prefix.pch
These classes or their likeness does not appear to be used in the original project from which I copied the other classes, is there any special use for them that would be dangerously stupid for me to delete them?
You can delete HelloWorldLayer. It's just the example scene/layer.
You would do well to leave the other files in. Any modifications you may have made to your old project's app delegate (such as which scene is passed to CCDirector's runWithScene method) should be re-done in the MyGameAppDelegate rather than replacing that with your old project's app delegate.
The reason is that the startup sequence for cocos2d has changed to support Retina devices, autorotation, changes in the iOS SDK, etc. The RootViewController handles autorotation, should you need that. Whether autorotation is enabled or not can be changed via GameConfig.h.

iPhone SDK: Localization of external class files?

I am adding some external classes to my already-localized project that include their own localization strings. For some reason the localization isn't working in these classes. It should be noted that I am not copying the external class files to my project, just adding a reference to them. I thought the problem could be that the external string file couldn't have the same name as the projects string file -- Localizable.strings -- so I changed it to something unique for the class. This didn't help. I also tried dragging the classes string files directly to the "Copy Bundle Resources" of my project to make sure that the strings in the bundle. Still no luck.
Interestingly, if I add these localized classes to a different project that isn't yet localized -- e.g. there isn't any Localizable.strings file in the project -- the class localizations work fine.
Suggestions?
You should use NSLocalizedStringFromTable instead of NSLocalizedString to extract strings from tables other than the default Localizable.strings.

How are objects defined in an XIB file and how are they created at runtime?

I've just purchased a Mac and am beginning to explore software development using Cocoa and Objective-C using XCode in Snow Leaped having come from a strong Microsoft and C# backgrund
All of the documentation and tutorials I have read use Interface Builder and XCode to create applications with user interfaces. My current understanding is that objects created by Interface Builder are in some way defined in an .xib file and created at runtime.
A bundle contains code and resources that accompany it. Is it right to say that an .xib file is in fact a bundle that contains UI resources and that this bundle is loaded (is that the correct verb?) at runtime and object instances are created?
If the abive is true is there any way I can see the code generated by Interface Builder and the point in code where these objects are created, without seeing this at least once I feel like there is a lot of "magic" happening and that isn't helping me at this stage of my learning.
Is there anything I should be reading to grasp the apparent paradigm-shift between C# / WinForms and Objective-C / Mac OS / Cocoa?
Is it right to say that an .xib file is in fact a bundle that contains UI resources and that this bundle is loaded (is that the correct verb?) at runtime and object instances are created?
No. A bundle is one of several specific directory structures, and a xib file is a regular file, not a directory.
A xib file contains descriptions of objects. When you compile the nib (usually as part of building your app), the nib compiler reads in the xib, creates the objects as described therein, and archives them into a nib, which isn't a bundle either.
When you load the nib in your application, the nib loader unarchives the objects and ensures all outlets are connected as they were in IB between its objects and to and from the File's Owner.
Don't worry about implementation details. Nibs Just Work. All you have to do is:
Create xib files. If you use version control, these are what you tell it to track.
Make sure they're in .lproj folders (so that localizers can create localized versions of them).
Let Xcode handle the rest.
The key thing to realize is that there isn't any code in the normal sense...at least, nib/xib UI resources are not simply contruscts of objective-c code that are merely generated by the Inteface Builder.
These are objects that are sort of "frozen" in the nibs and "unfrozen" when needed by the apps (or awakened, I guess, as the awakeFromNib would suggest). They are archived in xml/plist/etc form, rather than being a framework for generating objective-c source code.
Consider them objects that have been serialized as xml or other data.

Resources