小编Mik*_*keJ的帖子

快速正确使用getter和setter

有人可以帮助我理解快速使用getter和setter的正确用法.我得到的印象与Java说的不一样.

这是Swift存储和访问类变量的正确用法吗?

class Person {
    private var name: String

    init(name: String) {
        self.name = name
    }

    func setName(name: String) {
        self.name = name
    }

    func getName() -> String {
        return name
    }
}
Run Code Online (Sandbox Code Playgroud)

ios swift swift2

9
推荐指数
1
解决办法
4940
查看次数

设置在具体类中的接口中定义的只读属性

我有一个只读属性的接口

public interface IPerson
{
    string Name { get; }
}
Run Code Online (Sandbox Code Playgroud)

还有一个具体的课......

public class Person : IPerson
{

    public Person()
    {
        Name = "Person";
    }

    public string Name
    {
        get
        {
            return Name;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望Name只能在这个类的外部读取,但是如何在具体类中设置它?

错误:无法将Person.Name分配给.

如何在Person类中设置此属性的值?

c# inheritance properties interface

6
推荐指数
3
解决办法
9670
查看次数

以编程方式使用大小类设置字体大小

有一些关于这个的帖子,但似乎没有一个完整的解决方案。

通过 IB 使用自适应布局我可以轻松更改特定大小类的字体大小,但是我有一个使用 UILabels 的自定义视图,我想根据使用的大小类(使用 swift)以编程方式设置字体大小 - 有没有其他人有这个问题或遇到解决方案?

ios swift size-classes adaptive-layout

5
推荐指数
1
解决办法
2797
查看次数

Xcode 7 - 不兼容的块指针类型

这段代码在Xcode 6中运行良好,但现在无法在Xcode 7中编译.任何想法如何修复以及为什么这是Xcode 7中的一个问题?

不兼容的块指针类型将'void(^)(SKSpriteNode*__ strong,NSUInteger,BOOL*)'发送到'void(^ _Nonnull)类型的参数(SKNode*_Nonnull __strong,NSUInteger,BOOL*_Nonnull)'

[self.children enumerateObjectsUsingBlock:^(SKSpriteNode * node, NSUInteger idx,BOOL *stop)
{
    float parallaxRatio = [(NSNumber *)node.userData[@"ParallaxRatio"] floatValue];
    CGPoint childVelocity = CGPointMultiplyScalar(self.velocity, parallaxRatio);
    CGPoint offset = CGPointMultiplyScalar(childVelocity, deltaTime);
    node.position = CGPointAdd(node.position, offset);
}];
Run Code Online (Sandbox Code Playgroud)

objective-c ios xcode7

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

按下主页按钮后NSTimer不触发

我有一个NSTimer设置每秒发射.使用模拟器,通过按主页按钮导航离开应用程序后,这将正确调用eachSecond()方法.但是,在真正的iPhone 6上,一旦我离开,每个秒都不再被调用,直到应用程序再次打开.

为什么这在真实设备上表现不同?反正是否确保它会在这个用例中每秒发射一次?

它是一个健身应用程序,因此需要记录手机锁定或用户暂时离开时的持续时间.

谢谢,

lazy var timer = NSTimer()

fun init() {
   timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: #selector(RunViewController.eachSecond(_:)), userInfo: nil, repeats: true)
}

func eachSecond() {
 // update UI etc.
}
Run Code Online (Sandbox Code Playgroud)

nstimer ios swift

0
推荐指数
1
解决办法
103
查看次数