After I updated Xcode to 6.1 I get a couple of Compiler errors for my existing project.
I defined attributes like
let styleAttriutes = [
NSFontAttributeName : UIFont(...),
NSForgeroundColorAttributeName : UIColor.blackColor()
]
Error: "Could not find an overload for 'init' that accepts the supplied arguments"
So I declared the inferred Dictionary explicit adding : [NSString : Any] since all the key constants are of type NSString
and we have different values: UIFont
/ UIColor
and AnyObject
is also not allowed.
let styleAttriutes : [NSString : Any] = [ ...
Now the compiler is happy in this point.
The defined attribues are used in
text.boundingRectWithSize(size: CGSize, options: NSStringDrawingOptions, attributes: [NSObject : AnyObject!], context: NSStringDrawingContext!)
Since attributes of type [NSObject:AnyObject!]
are expected but I hand over attribues of type [NSString : Any]
the compiler complains:
Error : "'NSString' is not identical to 'NSObject'"
I tried to cast it using attributes as [NSObject : AnyObject]
but then I get runtime error.
Fatal Error : "Can't unsafeBitCast between types of differenz sizes".
Any suggestions?
I guess you're using UIFont
's init
method which returns an optional (ie can return nil
) since Xcode 6.1.
So try replacing UIFont(...)
with UIFont(...)!
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.