小编aka*_*kyy的帖子

如何在swift中解码HTML实体?

我从一个站点提取一个JSON文件,其中一个字符串是:

The Weeknd ‘King Of The Fall’ [Video Premiere] | @TheWeeknd | #SoPhi 
Run Code Online (Sandbox Code Playgroud)

如何将事物&#8216转换为正确的字符?

我已经制作了一个Xcode Playground来演示它:

import UIKit

var error: NSError?
let blogUrl: NSURL = NSURL.URLWithString("http://sophisticatedignorance.net/api/get_recent_summary/")
let jsonData = NSData(contentsOfURL: blogUrl)

let dataDictionary = NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: &error) as NSDictionary

var a = dataDictionary["posts"] as NSArray

println(a[0]["title"])
Run Code Online (Sandbox Code Playgroud)

json html-entities swift

113
推荐指数
10
解决办法
5万
查看次数

GitHub:什么是"wip"分支?

当我浏览GitHub存储库时,我经常看到"wip"分支(例如3.1.0-wip)."wip"是什么意思?

我无法在任何地方找到答案 - 无论是在Google上还是在GitHub上:帮助.

git branch github git-branch

89
推荐指数
2
解决办法
4万
查看次数

我怎样才能用渐变色调UIImage?

我到处搜索,但没有找到解决方案.我有图像1.如何以渐变方式对它们进行编程以获得图像2和3?以下是这些图片:

图像1,2,3

我通过Photoshop应用于它们的色调是简单的双色线性渐变.

我的问题是:如何以编程方式实现此效果?


解决方案: jrtc27给了我几乎成功的例子.我修复它(对于ARC)并使其可重用(使用UIImage的类别).就这个:

- (UIImage *)tintedWithLinearGradientColors:(NSArray *)colorsArr {
    CGFloat scale = self.scale;
    UIGraphicsBeginImageContext(CGSizeMake(self.size.width * scale, self.size.height * scale));
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(context, 0, self.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    CGContextSetBlendMode(context, kCGBlendModeNormal);
    CGRect rect = CGRectMake(0, 0, self.size.width * scale, self.size.height * scale);
    CGContextDrawImage(context, rect, self.CGImage);

    // Create gradient

    UIColor *colorOne = [colorsArr objectAtIndex:1]; // top color
    UIColor *colorTwo = [colorsArr objectAtIndex:0]; // bottom color


    NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, (id)colorTwo.CGColor, nil];
    CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
    CGGradientRef gradient …
Run Code Online (Sandbox Code Playgroud)

iphone core-graphics tint uiimage drawrect

29
推荐指数
4
解决办法
1万
查看次数

如何在带有Mantle的NSArray中指定子对象类型

如果我有一本字典

{
  name: "Bob",
  cars: [
    { make: "ford", year: "1972" },
    { make: "mazda", year: "2000" }
  ],
}
Run Code Online (Sandbox Code Playgroud)

和两个模型,如:

@interface CarModel : MTLModel

@property (nonatomic, strong) NSString *make;
@property (nonatomic, strong) NSString *year;

@end

@interface PersonModel : MTLModel

@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSArray *cars;

@end
Run Code Online (Sandbox Code Playgroud)

我如何使用Mantle以便我的人模型中的汽车阵列是CarModels?

frameworks ios github-mantle

27
推荐指数
3
解决办法
1万
查看次数

NSTask的实时输出

我有一个PHP脚本,它有mutliple sleep()命令.我想在我的应用程序中执行它NSTask.我的脚本看起来像这样:

echo "first\n"; sleep(1); echo "second\n"; sleep(1); echo "third\n";
Run Code Online (Sandbox Code Playgroud)

我可以使用通知异步执行我的任务:

- (void)awakeFromNib {
    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath: @"/usr/bin/php"];

    NSArray *arguments;
    arguments = [NSArray arrayWithObjects: @"-r", @"echo \"first\n\"; sleep(1); echo \"second\n\"; sleep(1); echo \"third\n\";", nil];
    [task setArguments: arguments];

    NSPipe *p = [NSPipe pipe];
    [task setStandardOutput:p];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskExited:) name:NSTaskDidTerminateNotification object:task];

    [task launch];

}

- (void)taskExited:(NSNotification *)notif {
    NSTask *task = [notif object];
    NSData *data = [[[task standardOutput] fileHandleForReading] readDataToEndOfFile];
    NSString *str = …
Run Code Online (Sandbox Code Playgroud)

macos nstask

20
推荐指数
2
解决办法
5678
查看次数

初始化NSMutableString对象的最佳方法是什么?

如果我提出以下问题.初始化NSMutableString类的最佳方法是什么?(所有实例都将在意外时间返回...所以我假设初始化如下:)

  1. 如果我事先知道工作量.(预期)

    NSMutableString *str1 = [NSMutableString stringWithString:@""];
    NSMutableString *str2 = [NSMutableString stringWithCapacity:0];
    NSMutableString *str3 = [NSMutableString stringWithCapacity:1000];
    NSMutableString *str4 = [NSMutableString string];
    
    for(int i = 0; i< 1000; i++)
    {
        //The following tasks.(Adding to the string to continue working.)
        [/*str1~str4*/ appendFormat:@"%d", i];
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 如果我事先不知道工作量.(意外)

    NSMutableString *str1 = [NSMutableString stringWithString:@""];
    NSMutableString *str2 = [NSMutableString stringWithCapacity:0];
    NSMutableString *str3 = [NSMutableString stringWithCapacity:1000];
    NSMutableString *str4 = [NSMutableString string];
    
    for(int i = 0; i< /*a large of size(unpredictable)*/ ; i++)
    {
        //The following tasks.(Adding to …
    Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsstring nsmutablestring

15
推荐指数
2
解决办法
2万
查看次数

AngularJS:如何在两个隔离的控制器和共享服务之间创建双向数据绑定?

我试图在两个隔离的控制器和一个共享服务(提供另一个隔离的范围)之间创建双向数据绑定:

app.factory("sharedScope", function($rootScope) {
    var scope = $rootScope.$new(true);
    scope.data = "init text from factory";
    return scope;
});

app.controller("first", function($scope, sharedScope) {
    $scope.data1 = sharedScope.data;
});

app.controller("second", function($scope, sharedScope) {
    $scope.data2 = sharedScope.data;
});
Run Code Online (Sandbox Code Playgroud)

小提琴:http://jsfiddle.net/akashivskyy/MLuJA/

当应用程序启动data1data2正确更新时init text from factory,如果我更改了其中任何一个,那么这些更改不会反映在这三个范围中.

我该如何绑定它们?

PS如果有一个更好的方法,而不是返回一个范围,仍然可以访问事件和观察功能(基本上不重写它们),请告诉我.:)

javascript angularjs angularjs-scope angularjs-controller

13
推荐指数
2
解决办法
1万
查看次数

NSWindowController showWindow:nil什么都不做

喜欢在标题中,[myWindowController showWindow:nil]不起作用.以下是您可能需要了解的一些事实:

  • 我的窗口控制器: KRAuthenticationWindowController
  • 接口构建器文件: AuthenticationWindow.xib
  • 文件的所有者是 KRAuthenticationWindowController
  • window 插座连接到窗口
  • Window delegate已连接到File的所有者
  • 窗口Visible at launch是未选中的
  • 窗口Release when closed也是未选中的

我的代码如下:

// KRApplicationDelegate.m

- (void)applicationDidFinishLaunching:(NSNotification *)notification {
    NSLog(@"%s",__PRETTY_FUNCTION__);
    KRAuthenticationWindowController *authWindowController = [[KRAuthenticationWindowController alloc] init];
    [authWindowController showWindow:nil];
    [[authWindowController window] makeKeyAndOrderFront:nil];
}

// KRAuthenticationWindowController.m

- (id)init {
    self = [super initWithWindowNibName:@"AuthenticationWindow"];
    if(!self) return nil;
    NSLog(@"%s",__PRETTY_FUNCTION__);
    return self;
}

- (void)loadWindow {
    [super loadWindow];
    [self.window setBackgroundColor:[NSColor colorWithDeviceWhite:0.73 alpha:1]];
    NSLog(@"%s",__PRETTY_FUNCTION__);
}

- (void)windowDidLoad {
    [super windowDidLoad];
    NSLog(@"%s",__PRETTY_FUNCTION__);
}

- …
Run Code Online (Sandbox Code Playgroud)

macos cocoa objective-c nswindow nswindowcontroller

10
推荐指数
1
解决办法
6257
查看次数

将(垂直)UIPageViewController嵌套在另一个(水平)UIPageViewcontroller中

我的问题很严重UIPageViewController.我想使用部分和子部分在我的应用程序中显示内容.所以,我创建了"两个"实例UIPageViewController- 水平(红色)和垂直(蓝色):

方案

之前我说过我已经创建了"两个"实例 - 这不是真的 - 可能有几十个实例,但同时只有两个实例,你知道我的意思.两个控制器都transitionStyle设置为UIPageViewControllerTransitionStyleScroll.

红色UIPageViewController负责部分之间的水平滚动,蓝色负责垂直滚动.

它们在分开时都可以工作,但是当我将垂直放置UIPageViewController在水平方向时,垂直方向会停止工作.

我的代码如下:


横向UIPageViewController创作

self.mainPageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:@{UIPageViewControllerOptionInterPageSpacingKey:[NSNumber numberWithFloat:0]}];
self.mainPageViewController.dataSource = self;
self.mainPageViewController.delegate = self;

self.pdfDocsURLs = @[ @{@"v":[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"1v" ofType:@"pdf"]],
                        @"h":[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"1h" ofType:@"pdf"]]},

                      @{@"v":[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"2v" ofType:@"pdf"]],
                        @"h":[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"2h" ofType:@"pdf"]]},

                      @{@"v":[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"3v" ofType:@"pdf"]],
                        @"h":[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"3h" ofType:@"pdf"]]}];

UIIndexedPageViewController *pvc …
Run Code Online (Sandbox Code Playgroud)

iphone nested objective-c uiviewcontroller uipageviewcontroller

8
推荐指数
1
解决办法
4194
查看次数

如何在可以生成视图但不是视图的结构中使用 @State 和 @Environment 属性?

我\xe2\x80\x99m 尝试创建一个视图样式来自定义我\xe2\x80\x99m 开发的自定义SwiftUI 视图。我声明了一个带有makeBody函数的协议,I\xe2\x80\x99m 将样式存储为@State属性以便可以更新,并且 I\xe2\x80\x99mmakeBody从视图内部调用。这项技术与 SwiftUI 已经做的非常相似,但是有一件事情我无法弄清楚。

\n

问题

\n

\xe2\x80\x99s 第一方视图样式具有的一个重要行为,我可以\xe2\x80\x99t 使用@State@Environment或任何其他 SwiftUI 属性包装器复制 \xe2\x80\x94 that\xe2\x80\x99s在自定义视图样式内。

\n

例如,我可以实现以下自定义ButtonStyle,仅将当前配色方案的值显示为按钮\xe2\x80\x99s 内容。

\n
struct MyButtonStyle: ButtonStyle {\n\n    @Environment(\\.colorScheme) var colorScheme\n\n    func makeBody(configuration: Configuration) -> some View {\n        Text(String(describing: colorScheme))\n    }\n\n}\n\nstruct MyView: View {\n\n    var body: some View {\n        Button("foo", action: {}).buttonStyle(MyButtonStyle())\n    }\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n

当我MyView使用.dark首选配色方案进行预览时, 的colorScheme属性MyButtonStyle被更新,makeBody 函数被再次调用,并且文本显示为 \xe2\x80\x9cdark\xe2\x80\x9d。这都是预料之中的。

\n …

ios swift swiftui

7
推荐指数
1
解决办法
899
查看次数