是否可以在iOS Playground中加载故事板?请按照以下问题中的步骤操作:
编译Main.storyboard使用
ibtool --compile MainMenu.nib MainMenu.storyboard
Run Code Online (Sandbox Code Playgroud)
将其添加到Resources游乐场的文件夹中.然后尝试加载它:
let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
Run Code Online (Sandbox Code Playgroud)
这导致错误:
Playground execution aborted: Execution was interrupted, reason: signal SIGABRT.
Run Code Online (Sandbox Code Playgroud)
XCode 7.3.1甚至XCode 8是否支持此功能?
我正在尝试移植使用反射的现有C#类(通用工厂),但我无法编译这段代码:
Type[] types = Assembly.GetAssembly(typeof(TProduct)).GetTypes();
foreach (Type type in types)
{
if (!typeof(TProduct).IsAssignableFrom(type) || type == typeof(TProduct))
...
Run Code Online (Sandbox Code Playgroud)
我试着查看.NET Framework for Windows Metro Style Apps和Assembly Class中的Reflection,在那里我发现了一个因为"使用System.Security.Permissions"而无法编译的示例.
看来ios 5.1和ios 6之间的CoreText实现存在一些差异,您可以从这两个屏幕截图中看到:
ios 6:

ios 5:

首先,文本颜色未正确应用.似乎在ios 5.1上kCTForegroundColorAttributeName要求你给它一个CGColor,而在ios 6上,传递一个UIColor就足够了.所以我通过将代码更改为:
[attributes setObject:(id)[color CGColor]
forKey:(NSString*)kCTForegroundColorAttributeName];
Run Code Online (Sandbox Code Playgroud)
其次,段落间距有点偏."视线"和"根据"之间的距离是11像素对25像素(在屏幕截图中测量).在两种情况下,段落间距都设置为5:
NSMutableData *styleSettingsArray = [NSMutableData data];
CGFloat spaceBefore,spaceAfter;
...
CTParagraphStyleSetting styleSettingB = {kCTParagraphStyleSpecifierParagraphSpacingBefore ,sizeof(CGFloat),&spaceBefore};
CTParagraphStyleSetting styleSettingA = {kCTParagraphStyleSpecifierParagraphSpacing ,sizeof(CGFloat),&spaceAfter};
[styleSettingsArray appendBytes:&styleSettingB length:sizeof(styleSettingB)];
[styleSettingsArray appendBytes:&styleSettingA length:sizeof(styleSettingA)];
...
if(styleSettingsArray.length > 0)
{
CTParagraphStyleRef paragraphStyleRef = CTParagraphStyleCreate([styleSettingsArray bytes], [styleSettingsArray length] / sizeof(CTParagraphStyleSetting));
[dictionary setObject:(__bridge id)(paragraphStyleRef) forKey:(NSString*)kCTParagraphStyleAttributeName];
CFRelease(paragraphStyleRef);
}
Run Code Online (Sandbox Code Playgroud)
paragraphStyleRef在控制台中的描述:
iOS 6:
CTParagraphStyle:
base writing direction = -1, alignment = 3, line break mode = …Run Code Online (Sandbox Code Playgroud) 我试图在不使用弹出窗口的情况下显示共享表,即没有源视图或箭头。
这是我的代码,从基本的单视图应用程序开始:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func didTapShare(_ sender: UIButton) {
let activity = UIActivityViewController(activityItems: ["banana"], applicationActivities: nil)
if UIDevice.current.userInterfaceIdiom == .pad {
activity.modalPresentationStyle = .formSheet
// activity.preferredContentSize = CGSize(width: 400, height: 400)
}
present(activity, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
这当然是崩溃的
"UIPopoverPresentationController (<UIPopoverPresentationController: 0x7fce07507900>) should have a non-nil sourceView or barButtonItem set before the presentation occurs."
Run Code Online (Sandbox Code Playgroud)
但我不希望它看起来像弹出窗口,或者有箭头——我希望它显示为表单,位于屏幕中间。
这是它在“照片”应用程序中的外观:

拿这个代码:
@interface SomeClass:NSObject
{
@private
NSString* Size;
}
@property NSString* Size;
@end
--------------------------
@implementation SomeClass
@synthesize Size;
- (void) something
{
Size = @"syntax error : Expected identifier or '(' ";
self.Size = @"works ok";
}
@end
Run Code Online (Sandbox Code Playgroud)
为什么这是语法错误?"Size"是保留字还是已在NSSObject中定义?我在两个单独的项目上得到了错误......