I tried archiving an NSAttributedString in Mac OSX 10.7 and then tried to unarchive it in iOS 4.. I get an error:
cannot decode object of class (NSParagraphStyle)
I see that there's no NSParagraphStyle in iOS. So my question is, is there a workaround or is it not possible to this?
Perhaps you could use the NSKeyedUnarchiver method setClass:forClassName and provide a class of your own to use for NSParagraphStyle. That class would have to implement initWithCoder: and you could either ignore it or try to replicate NSParagraphStyle with what's available on iOS (CTParagraphStyle which is quite difficult to work with).
Related
I am playing around with a mapping iOS app, using MapKit.
I would like to use Kingpin as a clustering library but I am using swift and the guide is objective-c only.
I create the cluster controller
var clusterController = KPClusteringController()
and add the delegate to the View Controller
class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate, KPClusteringControllerDelegate {
However I can't seem to be able to call the initWithMapView method, what am I doing wrong?
PS: the library should be imported correctly as both KPClusteringController and KPClusteringControllerDelegate are suggested by Xcode.
EDIT
I should be able to initialise the clustering manager like this
self.clusteringController = [[KPClusteringController alloc] initWithMapView:self.mapView]
However I have no idea how to do it in Swift :/ I would expect Xcode to give me a suggestion, but something might be loading properly.
Full kingpin doc here https://github.com/itsbonczek/kingpin
However I have no idea how to do it in Swift :/
As described in the Initialization section of Using Swift with Cocoa and Objective-C, in Swift you do this:
clusteringController = KPClusteringController(mapView:mapView)
The fact that you're using CocoaPods to manage this framework doesn't have any bearing on the situation. You just need to learn enough about Swift to translate from Objective-C.
I just learned about UICollectionView after creating the same functionality in a custom class. So I am thinking about using deleting all that code I wrote and just using UICollectionView.
I know my app gets a lot of installs on iOS 5. And I know a lot non tech savvy friends and family still have it installed.
I googled this and it says I can use some other's guys library(another thing I should have known before writing my custom class). But the answer was not definitive.
So my question is, does Apple include a bridge for iOS 5 or will my app just fail if I use UICollectionView?
I have my target deployment set to 5.0 and it is not giving me any warnings.
Venkat
UICollectionView is iOS6 only. You can include extra code to check for iOS6 and use your custom class on iOS5. But there is no way to use an actual UICollectionView in iOS5.'
Thats what that "other guy's library" does. It has an iOS5 compliant clone of UICollectionView and checks based on the OS which to use.
Maybe you want to try this as an alternative:
https://github.com/steipete/PSTCollectionView
I'd like to be able to set the lockscreen background image programmatically. I'm aware that this is only possible for jailbroken iOS devices.
Here are some things that I've tried:
Place a LockBackground.png in /private/var/mobile/Library/SpringBoard/. This works but requires a hard respring. notify_post("com.apple.language.changed"); doesn't work for a soft respring.
Use class-dump to dump private methods of UIKit. UIKit in 4.2 used to have a method called + (void)setDesktopImageData:(id)fp8; but it appears to be missing in 4.3 and above.
Is there anything that I'm missing?
I found this in the SpringBoard dump which I think will be of use to you:
In SBWallpaperView.h:
- (void)replaceWallpaperWithImage:(id)image;
And in SBUIController.h:
- (id)wallpaperView;
So you can do something like:
[(SBWallpaperView *)[SBUIController sharedInstance] wallpaperView] replaceWallpaperWithImage:anImage];
That's one way.
The other one I found was to use SBWallpaperView's + (void)noteWallpaperPreferencesChanged;, I'm not that sure about this one, but it seems like if you do what you did in the first thing you tried, and then use this instead of a respring, it might work.
I'm dealing with a very odd situation. I'm implementing Attributed Strings into my iOS application, and I had the warning going in that they are available iOS 3.2 and above. Because I still support 3.1.3 on iPhones, I knew I had to weakly link CoreText and probably so some compile time OS check before using them.
I weakly linked the framework, but out of curiosity I just used the class as is and ran it on a 3.1.3 device... and it works. What am I missing here, I'm so confused why this isn't crashing. I'm 100% sure this is a 3.1.3 device, but is NSMutableAttributedString a hidden class on 3.1.3, and thus actually does work because of the dynamic nature of objective-c ?
I am the author of the OHAttributedLabel class.
Thanks for using it!
The behavior you have is strange, as OHAttributedLabel uses the CoreText framework to draw the NSAttributedStrings on screen.
As CoreText is only available since iOS 3.2, I can't see how it would be possible for this to work under iOS 3.2, especially iOS 3.1.3…?
Did it really work, instead of just not crashing?
Depending on the setting, a non-existent class becomes just nil. Note that in Objective-C you can send a message to a nil. Then it just returns nil or 0. Then [[NSAttibutedString alloc] init] might just return nil, without crashing.
CoreText was introduced with iOS 3.2. If you weak link against it the app will start, but it will crash on the first instance on calling a CoreText function.
To still be compatible with earlier versions you CAN weak link and avoid CT code by drawing the text with Quartz instead. You would detect if CT exists on the device and use it if yes, otherwise you would have a crude fallback mechanism for your drawing.
Does anyone know what made Apple leave out NSAttributedString when turning AppKit into UIKit?
The reason I ask is that I would really like to use it in my iPhone app, and there appears to be no replacement or alternative than doing it myself...
It is possible to have mixed font attributes on a string - it's just a hell of a lot of work to to achieve something similar that was possible with a few lines of code with NSAttributedString.
Also, doing all this extra drawing code myself makes my table view cells really heavy, and really hurts performance.
Anyone got any ideas? Any genius's working on an opensource alternative to NSAttributedString?
NSAttributedString is now on the iPhone as of 4.0 Beta
The current from the documentation recommended way to do it is to use a UIWebView.
I don't know if this is still relevant for you, but Joe Hewitt has published his three20 library in the meantime, which contains TTStyledText and TTStyledTextLabel to fit your needs.
I'm afraid you're going to have to roll your own. If you're getting bogged down when doing table drawing, I'd probably switch to raw Quartz calls; try and dump all your drawing into a single view, and do all your complex string drawing within it. NSAttributedString is handy, but I don't think it's using all that much special AppKit-mojo to get much better performance than straight string drawing calls.
The answer above indicates that NSAttributedString is available on OS 4.0 and above, but per the documentation it's available on 3.2:
NSAttributedString Class Reference
Inherits from NSObject
Conforms to NSCoding, NSCopying, NSMutableCopying, NSObject (NSObject)
Framework /System/Library/Frameworks/Foundation.framework
Availability Available in iPhone OS 3.2 and later.
Companion guide Attributed String Programming Guide
Declared in NSAttributedString.h
Another approach would be to use a UIWebView with HTML. Or, if you are daring you can make use of the undocumented setHTML method on UITextView to set small snippets of formatted text...
To me this seems more like the future of where supporting formatted text will go, some way to leverage Webkit in outputting formatted strings.