小编Rob*_*Rob的帖子

为什么java多态在我的例子中不起作用

我有这4个java clases:1

public class Rect {
    double width;
    double height;
    String color;

    public Rect( ) {
        width=0;
        height=0;
        color="transparent";      
    }

    public Rect( double w,double h) {
        width=w;
        height=h;
        color="transparent";
    }

    double area()
    {
        return  width*height;
    } 
}
Run Code Online (Sandbox Code Playgroud)

2

public class PRect extends Rect{
    double depth;

    public PRect(double w, double h ,double d) {
        width=w;
        height=h;
        depth=d;
    }

    double area()
    {
        return  width*height*depth;
    }     
}
Run Code Online (Sandbox Code Playgroud)

3

public class CRect extends Rect{ 
    String color;

    public CRect(double w, double h ,String c) { …
Run Code Online (Sandbox Code Playgroud)

java polymorphism subclass superclass

6
推荐指数
1
解决办法
1877
查看次数

iOS - int(unsigned int)最大值是2147483647,unsigned int不起作用?

32位整数的最大值是:2 ^ 31-1 = 2147483647.但只有负数和正数.因为这个数字的一​​半是负数.所以真正的最大值是2 ^ 32-1 = 4294967295.但在这种情况下我们只使用正数.

好的,正常的int是负数和正数.我想只使用正数,因为我希望最大值为:4294967295.我将使用"unsigned int"而不是"int"

但这不行!最大值仍为2147483647.

这是一个简单的随机数生成器的代码:

-(Action for my button) {

unsigned int minNumber;

unsigned int maxNumber;

unsigned int ranNumber;

minNumber=[self.textFieldFrom.text intValue]; //getting numbers from my textfields
maxNumber=[self.textFieldTo.text intValue]; //Should i use unsigned intValue?

ranNumber=rand()%(maxNumber-minNumber+1)+minNumber;

NSString *str = [NSString stringWithFormat:@"%d", ranNumber];

self.label.text = str;

}
Run Code Online (Sandbox Code Playgroud)

这将查看:2147483647作为最大值.

怎么了?当我从textFields获取数字时,我应该使用unsigned intValue吗?

乔纳森


在这里你可以读到这个数字.:http://en.wikipedia.org/wiki/2147483647

int unsigned integer ios

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

Xcode 5中的OpenMP支持

我有一个专有的库(> 150,000行)量子力学C++代码,它依赖于OpenMP进行并行化.此代码用于使用Xcode 4.6及其真正的 GCC编译器进行编译,但Xcode 5附带的LLVM编译器似乎不支持OpenMP.我的代码是在Mac上开发的,但需要可移植到非Apple硬件,如大规模并行超级计算机,因此重写代码不是一种选择.有谁知道可以使用合适的编译器?非常感谢任何帮助.

xcode openmp

6
推荐指数
1
解决办法
3453
查看次数

完成处理程序在两次调用相同方法时导致EXC_BAD_ACCESS

我正在使用本教程研究一些IAP .

首先我用这个获取产品:

-(void)fetchAvailableProductsFirstLoad:(BOOL)firstTimeLoading {
    [[IAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) { ...
Run Code Online (Sandbox Code Playgroud)

帮助程序运行以下内容:

- (void)requestProductsWithCompletionHandler:(RequestProductsCompletionHandler)completionHandler {

    @synchronized(self) {
        // 1
        _completionHandler = [completionHandler copy];

        // 2
        _productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:_productIdentifiers];
        _productsRequest.delegate = self;
        [_productsRequest start];
    }
}
Run Code Online (Sandbox Code Playgroud)

当产品退回或失败时,会调用以下内容:

#pragma mark - SKProductsRequestDelegate

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {

    NSLog(@"Loaded list of products...");
    _productsRequest = nil;

    NSArray * skProducts = response.products;
    for (SKProduct * skProduct in skProducts) {
        NSLog(@"Found product: %@ %@ %0.2f",
              skProduct.productIdentifier,
              skProduct.localizedTitle,
              skProduct.price.floatValue);
    } …
Run Code Online (Sandbox Code Playgroud)

exc-bad-access storekit in-app-purchase ios skproduct

6
推荐指数
1
解决办法
2078
查看次数

如何使用MapKit和swift绘制多边形叠加层

我试图获取以下代码在地图上绘制多边形但由于某种原因它不起作用.我在这里出了什么问题?

import UIKit
import MapKit

class ViewController: UIViewController {

    @IBOutlet weak var mapView: MKMapView!
    override func viewDidLoad() {
        super.viewDidLoad()
        let initialLocation = CLLocation(latitude: 49.140838, longitude: -123.127886)
        centerMapOnLocation(initialLocation)
        addBoundry()
    }


    func addBoundry()
    {
        var points=[CLLocationCoordinate2DMake(49.142677,  -123.135139),CLLocationCoordinate2DMake(49.142730, -123.125794),CLLocationCoordinate2DMake(49.140874, -123.125805),CLLocationCoordinate2DMake(49.140885, -123.135214)]

        let polygon = MKPolygon(coordinates: &points, count: points.count)

        mapView.addOverlay(polygon)
    }


    let regionRadius: CLLocationDistance = 1000
    func centerMapOnLocation(location: CLLocation) {
        let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
            regionRadius * 2.0, regionRadius * 2.0)
        mapView.setRegion(coordinateRegion, animated: true)
    }


}


func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! { …
Run Code Online (Sandbox Code Playgroud)

mapkit point-in-polygon ios swift

6
推荐指数
1
解决办法
7754
查看次数

有角度的梯度层

我有自定义UIView类在Swift 2中呈现渐变.我正在努力制作一个有角度的渐变,以便从左上角到右下角绘制.有人可以帮我一点吗?

import UIKit

class GradientView: UIView {

    let gradientLayer = CAGradientLayer()

    override func awakeFromNib() {
        // 1
        self.backgroundColor = ColorPalette.White

        // 2
        gradientLayer.frame = self.bounds

        // 3
        let color1 = ColorPalette.GrdTop.CGColor as CGColorRef
        let color2 = ColorPalette.GrdBottom.CGColor as CGColorRef
        gradientLayer.colors = [color1, color2]

        // 4
        gradientLayer.locations = [0.0, 1.0]

        // 5
        self.layer.addSublayer(gradientLayer)
    }

}
Run Code Online (Sandbox Code Playgroud)

我怀疑这应该是别的,但无论我输入什么都没有变化.

gradientLayer.locations = [0.0, 1.0]
Run Code Online (Sandbox Code Playgroud)

gradient uiview cagradientlayer swift swift2

6
推荐指数
2
解决办法
7555
查看次数

同步嵌套的异步任务

我有嵌套的异步任务.此流程后面的函数:loadEpisodes(加载剧集列表) - >使用完成中的数组循环每个第一集并为特定剧集加载评论(另外一个异步任务).

问题是:在完成注释加载任务之前执行了comletion(fullyEpisodes).我试图使用Dispatch Group(第二个代码块),但它不起作用.

func loadComments(comletion: @escaping ([Episode]) -> Void){
loadEpisodes(completion: {
    episodes in
    var fullyEpisodes = [Episode]()
    for episode in episodes {
        WebService().load(resource: episode.comment, comletion: {
            comments in
            if let comments = comments {
                let _episode = Episode(id: episode.id, title: episode.title, comments: comments)
                fullyEpisodes.append(_episode)
                print("done")
            }
        })
    }
    comletion(fullyEpisodes)

})
}
Run Code Online (Sandbox Code Playgroud)

实施调度组:

func loadComments(comletion: @escaping ([Episode]) -> Void){
    loadEpisodes(completion: {
        episodes in
        var fullyEpisodes = [Episode]()
        let group = DispatchGroup()
        for episode in episodes {
            group.enter()
            WebService().load(resource: episode.comment, …
Run Code Online (Sandbox Code Playgroud)

asynchronous grand-central-dispatch ios swift

6
推荐指数
1
解决办法
565
查看次数

如何实现@property(class,readonly,copy,nonatomic)NSArray <NSString*>*_Nullable readableTypeIdentifiersForItemProvider;

尝试实现NSItemProviderReading协议.在Objective-C中,您如何满足:

@property(class, readonly, copy, nonatomic) NSArray<NSString *> * _Nullable readableTypeIdentifiersForItemProvider;
Run Code Online (Sandbox Code Playgroud)

我认为它NSArray需要UTI,但class参考是让我失望.

objective-c ios

6
推荐指数
1
解决办法
315
查看次数

如何解决EKEventStore上requestAccess(to:completion :)中的无限循环?

我正在打开,EKAuthorizationStatus但即使在requestAuthorisation(to:commit:)调用并返回true并且没有错误,switch语句仍然匹配.notDetermined大小写并且其中的递归产生无限循环.它让我疯了!

我试图找出requestAuthorisation(to:commit:)实际上是如何工作的,因为我觉得这个问题都是关于并发性的东西,但我找不到任何东西,所以我无法真正理解这种情况.

因为我的代码中的递归肯定是这个无限循环的一部分,所以我尝试了一种没有递归的方法.但是,由于EKAuthorizationStatus可能会在我的应用程序调用事件存储库之间发生变化,因此我希望先检查它,然后再对所有状态做出相应的响应.因此,我必须调用我的方法来切换授权状态,一个用于请求它并处理我班级中的任何错误,我不希望出于可读性,安全性和理智的原因.

private func confirmAuthorization(for entityType: EKEntityType) throws {
    switch EKEventStore.authorizationStatus(for: entityType) {
    case EKAuthorizationStatus.notDetermined:
        // Request authorisation for the entity type.
        requestAuthorisation(for: entityType)

        // Switch again.
        try confirmAuthorization(for: entityType)

    case EKAuthorizationStatus.denied:
        print("Access to the event store was denied.")
        throw EventHelperError.authorisationDenied

    case EKAuthorizationStatus.restricted:
        print("Access to the event store was restricted.")
        throw EventHelperError.authorisationRestricted

    case EKAuthorizationStatus.authorized:
        print("Acces to the event store granted.")
    }
}

private func requestAuthorisation(for entityType: EKEntityType) {
    store.requestAccess(to: …
Run Code Online (Sandbox Code Playgroud)

recursion infinite-loop eventkit ekeventstore swift

6
推荐指数
1
解决办法
193
查看次数

日期字符串与格式化程序期望的格式不匹配

只能在朋友的设备上重现此问题。该设备来自德国,并在“设置”中设置为德国地区。我无法在任何加拿大设备上复制。为什么尝试从 JSON 创建日期属性时失败?

安慰:

dataCorrupted(Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "60", intValue: nil), CodingKeys(stringValue: "expiration", intValue: nil)], debugDescription: "日期字符串与格式化程序期望的格式不匹配.",底层错误:nil))

结构:

struct TokenResponse: Decodable {
    var ticket : String
    var expiration : Date?
    var sessionId: String
}
Run Code Online (Sandbox Code Playgroud)

URLSession 内部:

do {
    let decoder = JSONDecoder()
    let formatter = DateFormatter()
    formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
    decoder.dateDecodingStrategy = .formatted(formatter)
    let json = try decoder.decode([String: TokenResponse].self, from: data)
}
catch {
    print(error)
}
Run Code Online (Sandbox Code Playgroud)

JSON:

{
   "60":{
      "ticket":"aVeryLongJWT",
      "expiration":"2022-02-04T22:00:34.8325102Z",
      "sessionId":"aUUID"
   }
}
Run Code Online (Sandbox Code Playgroud)

json date swift dateformatter jsondecoder

6
推荐指数
1
解决办法
1782
查看次数