How to include WebView in Objective C without crashing - objective-c

When I include a WebView component on a form in my Objective C project in XCode7 for a Cocoa application on OSX and try to compile, it compiles and then has a runtime error of:
NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (WebView) for key (NS.objects); the class may be defined in source code or a library that is not linked
What's the fix?

In XCode7, if you use a WebView widget, you have to add the framework. Go to the Project Navigator and click the first icon, which is your project icon. In the middle of your screen on that IDE then, you'll see General > Linked Frameworks and Libraries. Click the + and add WebKit.framework. Now when you compile, the linkage will be there and it will work.
The drawback I think is that it says it's a 10.11 component, and so if I want to deploy my app to a 10.9 system or 10.10 system, it won't work. I'm not 100% certain of this without testing, however, but do have this hunch.
ADDENDUM:
I set my project to be 10.8 compliant and then found I can run just fine on 10.8 all the way to the latest OSX.

Related

The “Swift Language Version” (SWIFT_VERSION) build setting error with project in Objective C

So i just went to build my app after adding in core data to update my app to store and fetch some information and i got this error. (I am using XCode 9.2)
The “Swift Language Version” (SWIFT_VERSION) build setting must be set
to a supported value for targets which use Swift. This setting can be
set in the build settings editor.
Now whats confusing me is this in an Objective C app and surely the swift version shouldn't matter. I have browsed some threads on here stating that i need to update build setting to Swift 3.0 or to set values to Yes then back to No, however i have none of these fields when i search for Swift in the search bar.
Is this just a bizarre bug or have i mistakenly added some swift code?
Any ideas would help, thanks.
I experienced this exact same issue after adding Core Data to an Objective-C framework I was working on.
I discovered that the reason I was getting the "Swift Language Version" warning was that the Code Generation language in the .xcdatamodel defaulted to Swift. Once I changed this back to Objective-C, the warning went away.
You can find this property in the File Inspector when you have the .xcdatamodel selected in the Project Navigator.
For Objective C Projects created using Xcode 8 and now opening in Xcode 9, it is showing the same error as mentioned in the question.
To fix that, Press the + button in Build Settings and select Add User-Defined Setting.
Then in the new row created add SWIFT_VERSION as key and 3.2 as value like below.
It will fix the error for objective c projects.

Xcode 8 Beta #import unexpected behavior

So I'm just coming back to programming for macOS after a few years hiatus, and have discovered the #import syntax. I created a sample program to test it out, but it's not working as my googling seems to suggest that it should.
Test project setup:
Open Xcode
File>New>Project...
Select the Cocoa Application template for macOS. Click Next
Name the project "ModuleTest", add organization name and organization Identifier. Select Objective-C as the language, check Use Storyboards, make sure "Create Document-Based Application", "Use Core Data", "Include Unit Tests" and "Include UI Tests" are all unchecked. Click Next and choose a save location. Don't create Git repository, and don't add to any project or workspace. Click Create.
In the Navigator, click on Main.storyboard.
From the Object Library, drag an AVKit Player View object onto the View of the View Controller Scene in the Storyboard.
Now at this point, we can see the symptom, which is that if you build the project, a window will pop open, but the player is missing from it, and the xcode output window shows a message such as
2016-08-16 09:07:46.465 ModuleTest[19778:4097187] Failed to set
(contentViewController) user defined inspected property on (NSWindow):
*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (AVPlayerView) for key (NSDestination); the class may be defined
in source code or a library that is not linked
This error occurs regardless of whether I put an #import AVKit; statement into AppDelegate.h, AppDelegate.m, ViewController.h, ViewController.m, or main.m. However, simply linking the AVKit.framework in the "Link Binary With Libraries" section of the project's Build Phases, solves the issue, no #import needed anywhere.
So what's going on? I thought #import was supposed to eliminate the need to manually link frameworks? Am I going through the process incorrectly? Is this happening because I'm using storyboards? Any ideas?
The problem is that there is no actual code that references the AVPlayerView. Try adding a single line of code that uses AVPlayerView and you'll notice that the error is gone.

Using Xamarin.Forms.Behaviors in XAML causes TargetInvocationException in iOS but not in Android

I'm doing a Xamarin.Forms app and I need to use Behaviors. I have added the Xamarin.Forms.Behaviors package to the project and added a behavior to the XAML of one page, so a command is executed when the selection of a ListView changes:
<b:Interaction.Behaviors>
<b:BehaviorCollection>
<b:EventToCommand Command="{Binding ItemSelectedCommand}" EventName="ItemSelected" />
</b:BehaviorCollection>
</b:Interaction.Behaviors>
This works nice on Android but the same project throws a TargetInvocationException when navigating to the same page under iOS. What could be causing this?
The iOS linker of Xamarin is more aggressive when stripping symbols/types that it thinks aren't used or referenced; and Xamarin.Forms XAML is usually the victim of this process.
There are two options to fix this:
- Change the stripping mode of the linker (right click on the Xamarin.iOS project -> Properties -> iOS Build tab -> Set Linker behavior to Link SDK assemblies only or Don't link). This will ensure the minimal amount of symbols (or none at all) are removed when creating the application package, the downside being that the app size will increment dramatically.
- Create a code file that manually references those types (for example creating instances that aren't used) so they aren't automatically stripped. Libraries like MvvmCross use this approach.
The latter method is the recommended although it has a bit more of work to do. The former one should be used when you are using third party libraries with lots of types that are getting stripped and it would take more work to reference all of them.

Xcode 6 does not localize Interface Builder

Xcode 6 Beta 4 using Swift.
I use localization in my project and I have experience in localization from Xcode 5.
Localization in program code using NSLocalizedString() works fine.
Localization of Info.plist strings work fine, too.
When it comes to localize the strings from Interface Builder it only works in Interface Builder preview but not in simulator and not on my device (iPhone 5S).
Am I missing something or can anyone confirm this as a bug in in Xcode 6 Beta 4?
It seems like the problem is with the size classes.
If "Use Size Classes" checkbox is enabled for storyboard, the Xcode actually generates 3 versions of it ("<Name>.storyboard", "<Name>~ipad.storyboard" and "<Name>~iphone.storyboard").
So iOS just tries to load .strings file which name matches the name of active storyboard (<Name>~iphone.strings in case app is running on the iPhone). And being not able to find that file, it falls back to Base localization.
There are a couple of ways to work around this bug:
The most obvious one. Just disable size classes for the storyboard.
If you need size classes, you can add localized <Name>~iphone.strings and <Name>~ipad.strings files to the project manualy and copy your translations over.
Apple release notes of XCode 6 GM covers this :
Localization:
A storyboard or XIB will not localize correctly if all of the following three conditions are true:
The storyboard or XIB uses size classes.
The base localization and the build target are set to Universal.
The build targets iOS 7.0.

Default implementation of splitViewController:shouldHideViewController:inOrientation:

Hi, the default implementation of splitViewController:shouldHideViewController:inOrientation: method in the UISplitViewControllerDelegate protocol is as given below. -
return UIInterfaceOrientationIsPortrait(orientation);
How to locate this implementation in Xcode? I can go over to the declaration of this method in UISplitViewController.h file in Xcode, but not the implementation. So how does one know the default implementation of any built-in method?
The method shouldHideViewController was only introduced in iOS 5.
If your target build settings 'deployment target' are set to anything before iOS 5, the Xcode editor won't offer you this method through autocompletion (or any other that aren't available to your target iOS version).
To check the iOS Deployment Target in Xcode, select your target, and look under the Summary tab. Make sure this is at least iOS 5.
For some methods only introduced in iOS, such as setTintColor methods, you can dynamically check the version in your code, but in this example (shouldHideViewController), I think you're going to want to choose to use it, and go with iOS 5 only, or choose to not use it and use popovers.